mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 12:44:58 +00:00
fix: use semaphore for thread safety in Start method
This commit is contained in:
@@ -30,6 +30,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
private Timer PollTimer;
|
private Timer PollTimer;
|
||||||
|
|
||||||
|
private SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// GenericCommunicationMonitor constructor
|
/// GenericCommunicationMonitor constructor
|
||||||
///
|
///
|
||||||
@@ -201,14 +203,21 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
private void BeginPolling()
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user