Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the WaitHandle was set?

Tags:

c#

waithandle

I have a WaitHandle and I would like to know how to check if the WaitHandle has already been set or not.

Note: I can add a bool variable and whenever Set() method is used set the variable to true, but this behaviour must be built in WaitHandle somewhere.

Thanks for help!

like image 408
Martin Vseticka Avatar asked Jul 22 '10 20:07

Martin Vseticka


People also ask

How to use WaitHandle in c#?

static WaitHandle[] waitHandles = new WaitHandle[] { new AutoResetEvent(false), new AutoResetEvent(false) }; // Define a random number generator for testing. static Random r = new Random(); static void Main() { // Queue up two tasks on two different threads; // wait until all tasks are completed.

What is ManualResetEvent and AutoResetEvent in C#?

The ManualResetEvent is the door, which needs to be closed (reset) manually. The AutoResetEvent is a tollbooth, allowing one car to go by and automatically closing before the next one can get through.


1 Answers

Try WaitHandle.WaitOne(0)

If millisecondsTimeout is zero, the method does not block. It tests the state of the wait handle and returns immediately.

like image 156
SwDevMan81 Avatar answered Oct 06 '22 14:10

SwDevMan81