private void DataRxPollThread(object threadData) { try { threadCtrl.Init(); threadCtrl.RunningThread = true; SharedObjects.Log.Write(Logging.MsgType.Debug, "CommManager", "Starting Thread"); while (!threadCtrl.ExitThread) { if (threadCtrl.PauseThread) { threadCtrl.IdleThread = true; SharedObjects.Log.Write(Logging.MsgType.Debug, "CommManager", "Pausing Thread"); threadCtrl.EventPause.WaitOne(); threadCtrl.IdleThread = false; if (threadCtrl.ExitThread) { break; } } int bytesToRead = ComPort.BytesToRead; if (bytesToRead > 0) { byte[] bytes = new byte[bytesToRead]; ComPort.Read(bytes, 0, bytesToRead); if (fp_rxDataInd != null) { fp_rxDataInd(bytes, bytes.Length); } } else { Thread.Sleep(10); } } } catch (Exception ex) { msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Task Thread Problem.\n" + ex.Message + "\nCommManager\n"); } SharedObjects.Log.Write(Logging.MsgType.Debug, "CommManager", "Exiting Thread"); threadCtrl.Exit(); }
private void TaskThread(object threadData) { try { bool stopped = false; ThreadCtrl.Init(); ThreadCtrl.RunningThread = true; SharedObjects.Log.Write(Logging.MsgType.Debug, moduleName, "Starting Thread"); while (!stopped) { if (ThreadCtrl.ExitThread) { break; } if (ThreadCtrl.PauseThread) { ThreadCtrl.IdleThread = true; SharedObjects.Log.Write(Logging.MsgType.Debug, moduleName, "Pausing Thread"); ThreadCtrl.EventPause.WaitOne(); ThreadCtrl.IdleThread = false; if (ThreadCtrl.ExitThread) { break; } } switch (WaitHandle.WaitAny( new WaitHandle[3] { ThreadCtrl.EventExit, ThreadCtrl.EventPause, DataQueue.qDataReadyEvent })) { case 0: stopped = true; break; case 1: ThreadCtrl.EventPause.Reset(); SharedObjects.Log.Write(Logging.MsgType.Debug, moduleName, "Resuming Thread"); break; case 2: DataQueue.qDataReadyEvent.Reset(); QueueDataReady(); break; default: stopped = true; break; } } } catch (Exception ex) { m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Task Thread Problem.\n" + ex.Message + "\nRspDataInThread\n"); } SharedObjects.Log.Write(Logging.MsgType.Debug, moduleName, "Exiting Thread"); ThreadCtrl.Exit(); }
private void TaskThread(object threadData) { try { bool flag = false; threadCtrl.Init(); threadCtrl.RunningThread = true; SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Starting Thread"); while (!flag) { if (threadCtrl.ExitThread) { break; } if (threadCtrl.PauseThread) { threadCtrl.IdleThread = true; SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Pausing Thread"); threadCtrl.EventPause.WaitOne(); threadCtrl.IdleThread = false; if (threadCtrl.ExitThread) { break; } } if (!stopWaitMsg) { switch (WaitHandle.WaitAny( new WaitHandle[3] { threadCtrl.EventExit, threadCtrl.EventPause, dataQ.qDataReadyEvent })) { case 0: flag = true; break; case 1: threadCtrl.EventPause.Reset(); SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Resuming Thread"); break; case 2: dataQ.qDataReadyEvent.Reset(); QueueDataReady(); break; default: flag = true; break; } continue; } switch (WaitHandle.WaitAny( new WaitHandle[3] { threadCtrl.EventExit, threadCtrl.EventPause, stopWaitSuccessEvent }, new TimeSpan(0, 0, 0, 40))) { case 0: flag = true; break; case 1: threadCtrl.EventPause.Reset(); SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Resuming Thread"); break; case 2: stopWaitSuccessEvent.Reset(); stopWaitEvent = (HCIStopWait.StopWaitEvent)null; stopWaitMsg = false; break; case 258: if (DeviceRxStopWaitCallback != null) { DeviceRxStopWaitCallback(false, (HCIStopWait.StopWaitEvent)null); } if (stopWaitEvent != null) { string msg = "Message Response Timeout\nName = " + devUtils.GetOpCodeName((ushort)stopWaitEvent.TxOpcode) + "\nOpcode = 0x" + ((ushort)stopWaitEvent.TxOpcode).ToString("X4") + "\nTx Time = " + stopWaitEvent.TxTime + "\n"; if (DisplayMsgCallback != null) { DisplayMsgCallback(SharedAppObjs.MsgType.Error, msg); } if (stopWaitEvent.Callback == null) { msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg); ClearTxQueueQuestion(); } if (ShowProgressCallback != null) { ShowProgressCallback(false); } if (stopWaitEvent.Callback != null) { stopWaitEvent.Callback(false, stopWaitEvent.CmdName); } } stopWaitEvent = (HCIStopWait.StopWaitEvent)null; stopWaitMsg = false; break; default: flag = true; break; } } } catch (Exception ex) { msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Task Thread Problem.\n" + ex.Message + "\nTxDataOutThread\n"); } SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Exiting Thread"); threadCtrl.Exit(); }