mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-12 03:57:27 +00:00
fix: use semaphore for thread safety in Start method
This commit is contained in:
parent
c1d62ea5d4
commit
eeb106c489
1 changed files with 14 additions and 5 deletions
|
|
@ -30,6 +30,8 @@ namespace PepperDash.Essentials.Core
|
|||
|
||||
private Timer PollTimer;
|
||||
|
||||
private SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor
|
||||
///
|
||||
|
|
@ -201,7 +203,9 @@ namespace PepperDash.Essentials.Core
|
|||
|
||||
private void BeginPolling()
|
||||
{
|
||||
lock (_pollTimerLock)
|
||||
try
|
||||
{
|
||||
semaphore.Wait();
|
||||
{
|
||||
if (PollTimer != null)
|
||||
{
|
||||
|
|
@ -211,6 +215,11 @@ namespace PepperDash.Essentials.Core
|
|||
PollTimer = new Timer(o => Poll(), null, 0, PollTime);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop the poll cycle
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue