Is it possible to check the blocking state for C# System.Threading.AutoResetEvent or System.Threading.ManualResetEvent before calling WaitOne() ?
An EventWaitHandle doesn't have a "blocking state". It is set or reset, nothing else. And no, you cannot check that any other way than by calling WaitOne().
You can pass a 0 for the time-out argument to avoid blocking. That's often a very bad idea because it says nothing about the state of the event after the WaitOne() call returns. It might have changed a nanosecond after that. This causes a very nasty kind of bug called "threading race". A Heisenbug.
Use
public virtual bool WaitOne(
TimeSpan timeout
)
with timeout 0. According to MSDN it will return the state of the WaitHandle immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With