There are two CRITERIA in my program which decides whether a thread should wait or continue.
First Criterion: Change in an XML file. I have a file watcher which sets an AutoResetEvent
(_waitTillXmlChanges.Set()
) if the XML file changes and hence the thread should proceed.
Second Criterion: Due Date has come. If today is the date when the file transfer should take place then, the second criterion has met and hence the thread should proceed.
My Current Code:
var waitTillNextWakeUpDay = NextWakeUpDay - DateTime.Now;
//SPURIOS WAKE-UP calls happening here
_waitTillXmlChanges.WaitOne(waitTillNextWakeUpDay);
I understand that to avoid the spurious wake-up calls, a while-loop
is put around the WaitOne()
so that the thread goes into waiting mode again if it woke-up by mistake.
PROBLEM: I don't understand how should I implement the failsafe while loop around the WaitOne()
(which depends on two conditions).
Important Clue: Since I am printing on a log file whenever the XML file changes so, I can say that the fake wake-up calls are not because of the FileWatcher. Most probably, the problem is in the line _waitTillXmlChanges.WaitOne(waitTillNextWakeUpDay)
, which is not able to wait for a timespan of waitTillNextWakeUpDay
(which is around 1 day) and gets awake in every 15-30 minutes.
The above code is working as desired on my PC but the problem of spurious wake-up is coming on an another PC.