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