I was dealing with code that has some calls to ManualResetEvent
's WaitOne call.
From the MSDN documentation,
If timeout is zero, the method does not block. It tests the state of the wait handle and returns immediately.
Now, this is my piece of code:
Console.WriteLine("abc");
if (manualResetEventObject.WaitOne(0, false))
return;
Console.WriteLine("def");
//More function calls
Here, based on the doc, I'd expect it to print abc, return from WaitOne and print def. manualResetEventObject
is not signaled at this point, and so WaitOne
's return value should be false.
However, def is never printed and I see a ThreadInterruptedException
being thrown (there's a try
/catch
block enclosing this).
I don't understand why this doesn't print def or why the exception is thrown. What exactly is going on here ?