//循环

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

相关文章:

  • 2021-08-02
  • 2021-12-12
  • 2021-12-12
  • 2021-08-29
  • 2021-12-12
  • 2021-05-06
  • 2021-12-12
猜你喜欢
  • 2022-12-23
  • 2021-12-12
  • 2021-12-12
  • 2022-02-15
  • 2021-04-18
  • 2022-01-20
相关资源
相似解决方案