private void Button_Click_2(object sender, RoutedEventArgs e) { try { if (isCj201 == false) { return; } if (cj201Thread != null) { cj201Thread.Abort(); cj201Thread.DisableComObjectEagerCleanup(); cj201Thread = null; } cj201Thread = new Thread(delegate() { isCj201 = false; showInfo("正在检测,请稍后..."); //燃气读卡器 Thread.Sleep(1000); string str = DeviceState.SendCJ201State(); if (str == null) { setTextBlockText(cj201lbl, "正常"); } else { setTextBlockText(cj201lbl, "异常:" + str.Remove(0, 2) + " " + ExceptionInfo(str)); } showInfo("设备状态"); isCj201 = true; }); cj201Thread.Start(); } catch (ThreadAbortException ae) { log.Write("error:" + ae.Message); } catch (Exception ex) { log.Write("error:" + ex.Message); } }
private void checkState() { try { string str = DeviceState.SendCRT310State(); if (str == null) { setTextBlockText(crt310lbl, "正常"); } else { setTextBlockText(crt310lbl, "异常:" + str.Remove(0, 2) + " " + ExceptionInfo(str)); } str = DeviceState.SendZT598State(); if (str == null) { setTextBlockText(zt598lbl, "正常"); } else { setTextBlockText(zt598lbl, "异常:" + str.Remove(0, 2) + " " + ExceptionInfo(str)); } str = DeviceState.SendPrintState(); if (str == null) { setTextBlockText(printlbl, "正常"); } else { setTextBlockText(printlbl, "异常:" + str.Remove(0, 2) + " " + ExceptionInfo(str)); } str = DeviceState.SendCJ201State(); if (str == null) { setTextBlockText(cj201lbl, "正常"); } else { setTextBlockText(cj201lbl, "异常:" + str.Remove(0, 2) + " " + ExceptionInfo(str)); } str = DeviceState.SendCRT603State(); if (str == null) { setTextBlockText(crt603lbl, "正常"); } else { setTextBlockText(crt603lbl, "异常:" + str.Remove(0, 2) + " " + ExceptionInfo(str)); } showInfo("设备状态"); } catch (Exception ex) { log.Write("error:设备检测异常:" + ex.Message); showInfo("设备检测异常"); } }