//检测仪器状态的线程 private void CheckInstument() { double temperature; int count = 0; if (CheckRamanInstrument() == false) //没有检查到仪器 { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new InstrumentStateDelegate(InstrumentState), double.MinValue, null); return; } if (RamanInstrument.Reconnect() == false) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new InstrumentStateDelegate(InstrumentState), double.MinValue, RamanInstrument.ErrorString); return; } while (true) { temperature = RamanInstrument.GetTemperature(); if (temperature == double.MaxValue) { RamanInstrument.Connect(); temperature = RamanInstrument.GetTemperature(); } if (temperature == double.MaxValue) //仪器没连接上 { if (count < 2) //重复3次,如果还是没有取到温度,则表示仪器连接错误了 { count++; } else { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new InstrumentStateDelegate(InstrumentState), double.MinValue, null); break; } } else { count = 0; } Dispatcher.BeginInvoke(DispatcherPriority.Normal, new InstrumentStateDelegate(InstrumentState), temperature, null); System.Threading.Thread.Sleep(1000); if (Environment.TickCount - SettingData.lastOperateTime > SettingData.settingData.runing_para.InstrumentTimeOut * 60 * 1000) //超过设定时间没有操作了,需要重新连接 { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new InstrumentStateDelegate(InstrumentState), double.MinValue, null); RamanInstrument.DisConnect(); break; } } }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (CommonMethod.QuestionMsgBox("确认退出NirIdentifier软件?") == false) { e.Cancel = true; return; } if (checkTread != null && checkTread.IsAlive) { checkTread.Abort(); } RamanInstrument.DisConnect(); }