//循环
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;
}