mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-12 03:57:27 +00:00
fix: only create poll timer if it doesn't exist
This commit is contained in:
parent
428f9f34bd
commit
7a4224e52a
1 changed files with 16 additions and 5 deletions
|
|
@ -40,6 +40,7 @@ namespace PepperDash.Essentials.Core
|
||||||
|
|
||||||
long PollTime;
|
long PollTime;
|
||||||
CTimer PollTimer;
|
CTimer PollTimer;
|
||||||
|
CCriticalSection pollCriticalSection = new CCriticalSection();
|
||||||
string PollString;
|
string PollString;
|
||||||
Action PollAction;
|
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
|
// Start polling and set status to unknow and let poll result update the status to IsOk when a response is received
|
||||||
Status = MonitorStatus.StatusUnknown;
|
Status = MonitorStatus.StatusUnknown;
|
||||||
Start();
|
Start();
|
||||||
BeginPolling();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BeginPolling()
|
void BeginPolling()
|
||||||
{
|
{
|
||||||
Poll();
|
try{
|
||||||
PollTimer = new CTimer(o => Poll(), null, PollTime, PollTime);
|
pollCriticalSection.Enter();
|
||||||
|
|
||||||
|
if (PollTimer != null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PollTimer = new CTimer(o => Poll(), null, 0, PollTime);
|
||||||
|
}
|
||||||
|
finally{
|
||||||
|
pollCriticalSection.Leave();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Stop()
|
public override void Stop()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue