diff --git a/src/PepperDash.Essentials.Core/Monitoring/GenericCommunicationMonitor.cs b/src/PepperDash.Essentials.Core/Monitoring/GenericCommunicationMonitor.cs index d012ff2c..a3a427f1 100644 --- a/src/PepperDash.Essentials.Core/Monitoring/GenericCommunicationMonitor.cs +++ b/src/PepperDash.Essentials.Core/Monitoring/GenericCommunicationMonitor.cs @@ -30,6 +30,8 @@ namespace PepperDash.Essentials.Core private Timer PollTimer; + private SemaphoreSlim semaphore = new SemaphoreSlim(1, 1); + /// /// GenericCommunicationMonitor constructor /// @@ -201,14 +203,21 @@ namespace PepperDash.Essentials.Core private void BeginPolling() { - lock (_pollTimerLock) + try { - if (PollTimer != null) + semaphore.Wait(); { - return; - } + if (PollTimer != null) + { + return; + } - PollTimer = new Timer(o => Poll(), null, 0, PollTime); + PollTimer = new Timer(o => Poll(), null, 0, PollTime); + } + } + finally + { + semaphore.Release(); } }