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;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM