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