C#线程启动、暂停、恢复、停止怎么实现

//循环

Thread    thread=new Thread(() => {
string vv = "";
while (true)
{

if (on_off)
{
getWeightEvent = new ManualResetEvent(false);
getWeightEvent.WaitOne();
}

//多线程非UI报错处理

Form.Dispatcher.BeginInvoke(() =>
{
vv = tfw.GetWeight("");
});

Thread.Sleep(1000);

}
});
thread.IsBackground = true;
thread.Start();
on_off = true;

if (Form.UseScale.IsChecked && (thread.ThreadState & ThreadState.AbortRequested) == 0)//开始
{
on_off = false;
getWeightEvent.Set();
}

else if (thread.ThreadState != ThreadState.Running)//暂停
{
on_off = true;
}

原文地址:https://www.cnblogs.com/yyl001/p/14296809.html