From 7a4224e52a6e2cc953ac01ff78f472942e898a9c Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Fri, 11 Apr 2025 15:14:28 -0500 Subject: [PATCH] fix: only create poll timer if it doesn't exist --- .../Monitoring/GenericCommunicationMonitor.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Monitoring/GenericCommunicationMonitor.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Monitoring/GenericCommunicationMonitor.cs index edb4c31b..ab3d8b37 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Monitoring/GenericCommunicationMonitor.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Monitoring/GenericCommunicationMonitor.cs @@ -40,6 +40,7 @@ namespace PepperDash.Essentials.Core long PollTime; CTimer PollTimer; + CCriticalSection pollCriticalSection = new CCriticalSection(); string PollString; Action PollAction; @@ -176,15 +177,25 @@ namespace PepperDash.Essentials.Core { // Start polling and set status to unknow and let poll result update the status to IsOk when a response is received Status = MonitorStatus.StatusUnknown; - Start(); - BeginPolling(); + Start(); } } void BeginPolling() - { - Poll(); - PollTimer = new CTimer(o => Poll(), null, PollTime, PollTime); + { + try{ + pollCriticalSection.Enter(); + + if (PollTimer != null) + { + return; + } + + PollTimer = new CTimer(o => Poll(), null, 0, PollTime); + } + finally{ + pollCriticalSection.Leave(); + } } public override void Stop()