From 86d444ea04bfbe3d7b4a939f2b8e987381543d6d Mon Sep 17 00:00:00 2001 From: luosheng Date: Fri, 14 Jul 2023 07:27:37 +0800 Subject: [PATCH] Fix --- .../Modbus.Net/Controller/FifoController.cs | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/Modbus.Net/Modbus.Net/Controller/FifoController.cs b/Modbus.Net/Modbus.Net/Controller/FifoController.cs index 3baf686..72efbb3 100644 --- a/Modbus.Net/Modbus.Net/Controller/FifoController.cs +++ b/Modbus.Net/Modbus.Net/Controller/FifoController.cs @@ -47,17 +47,17 @@ namespace Modbus.Net /// protected override void SendingMessageControlInner() { - try + _taskCycleSema?.WaitOne(); + while (!_taskCancel) { - _taskCycleSema?.WaitOne(); - while (!_taskCancel) + if (AcquireTime > 0) { - if (AcquireTime > 0) - { - Thread.Sleep(AcquireTime); - } - bool sendSuccess = false; - lock (WaitingMessages) + Thread.Sleep(AcquireTime); + } + bool sendSuccess = false; + lock (WaitingMessages) + { + try { if (_currentSendingPos == null) { @@ -84,21 +84,23 @@ namespace Modbus.Net } } } - if (sendSuccess) + catch (ObjectDisposedException e) { - _taskCycleSema?.WaitOne(); + logger.LogError(e, "Controller _currentSendingPos disposed"); + _currentSendingPos = null; + sendSuccess = true; + } + catch (Exception e) + { + logger.LogError(e, "Controller throws exception"); + _taskCancel = true; } } + if (sendSuccess) + { + _taskCycleSema?.WaitOne(); + } } - catch (ObjectDisposedException) - { - //ignore - } - catch (Exception e) - { - logger.LogError(e, "Controller throws exception"); - } - } ///