I'm trying to do something like this:
EventWaitHandle handler = new EventWaitHandle(false, EventResetMode.AutoReset)
//This code will run in background thread
private void AsyncWait() {
while (true) {
handler.WaitOne();
//LongRunningOperation()
}
}
Elsewhere in the code, there will be methods that call:
handler.Set()
So the LongRunningOperation() is executed..
Problem is, the handler.Set()
can be called again while the AsyncWait()
thread is running the LongRunningOperation()
This makes the LongRunningOperation()
will never be called whenever the handler.Set()
is called while AsyncWait()
is still executing LongRunningOperation()
How to make this right? :(