protected override void Stop() { if (_stopFlag == 1) { return; } _cancellation.Cancel(); Thread.MemoryBarrier(); ModuleUtils.StopThreadWork(_receiveThread); //如果两个队列在被锁的状态则释放锁 _engineMessageQueue.FreeBlocks(); _statusMessageQueue.FreeBlocks(); _callBackMessageQueue.FreeBlocks(); // 发送停止消息,该消息只是为了释放被Receive阻塞的线程,并不会真的被处理 ControlMessage stopMessage = new ControlMessage(MessageNames.CtrlAbort, CommonConst.BroadcastSession); UpLinkMessenger.Send(stopMessage); Thread.MemoryBarrier(); ModuleUtils.StopThreadWork(_engineMessageListener); ModuleUtils.StopThreadWork(_statusMessageListener); ModuleUtils.StopThreadWork(_callBackMessageListener); ModuleUtils.StopThreadWork(_receiveThread); ZombieCleaner.Stop(); UpLinkMessenger.Clear(); Thread.VolatileWrite(ref _stopFlag, 1); GlobalInfo.LogService.Print(LogLevel.Info, CommonConst.PlatformLogSession, "Message transceiver stopped."); }
protected override void Start() { _cancellation = new CancellationTokenSource(); _receiveThread = new Thread(SynchronousReceive) { Name = "RemoteMessageReceiver", IsBackground = true }; _receiveThread.Start(); ZombieCleaner.Start(); _engineMessageListener = new Thread(MessageProcessingLoop) { Name = "EngineMessageListener", IsBackground = true }; _statusMessageListener = new Thread(MessageProcessingLoop) { Name = "EngineMessageListener", IsBackground = true }; _engineMessageListener.Start(_engineMessageQueue); _statusMessageListener.Start(_statusMessageQueue); }
protected override void Start() { _cancellation = new CancellationTokenSource(); _receiveThread = new Thread(SynchronousReceive) { Name = "RemoteMessageReceiver", IsBackground = true }; _receiveThread.Start(); ZombieCleaner.Start(); _engineMessageListener = new Thread(MessageProcessingLoop) { Name = "EngineMessageListener", IsBackground = true }; _statusMessageListener = new Thread(MessageProcessingLoop) { Name = "StatusMessageListener", IsBackground = true }; _callBackMessageListener = new Thread(MessageProcessingLoop) { Name = "CallBackMessageListener", IsBackground = true }; _engineMessageListener.Start(_engineMessageQueue); _statusMessageListener.Start(_statusMessageQueue); _callBackMessageListener.Start(_callBackMessageQueue); GlobalInfo.LogService.Print(LogLevel.Info, CommonConst.PlatformLogSession, "Message transceiver started."); }
protected override void Stop() { _cancellation.Cancel(); ModuleUtils.StopThreadWork(_receiveThread); //如果两个队列在被锁的状态则释放锁 _engineMessageQueue.FreeLock(); _statusMessageQueue.FreeLock(); ModuleUtils.StopThreadWork(_engineMessageListener); ModuleUtils.StopThreadWork(_statusMessageListener); ZombieCleaner.Stop(); }