Exactly when does WaitHandle WaitOne(int timeout)
return? Does it return when the timeout has elapsed? I see some code online which suggests polling WaitOne()
when implementing logic which does some cleanup before exiting. This implies that WaitOne() does not return when the timeout elapses; instead it returns whether or not it is signaled immediately after it is called.
public void SomeMethod()
{
while (!yourEvent.WaitOne(POLLING_INTERVAL))
{
if (IsShutdownRequested())
{
// Add code to end gracefully here.
}
}
// Your event was signaled so now we can proceed.
}
What I am trying to achieve here is a way to signal the WaitHandle
using a CancellationToken
while it is blocking the calling thread.