ManualResetEvent
behaves exactly as the name tells us: It has to be reset manually!
Manual reset events are like gates. When the event is not signaled, threads that wait on it will block. When the event is signaled, all waiting threads are released, and the event remains signaled (that is, subsequent waits do not block) until its Reset method is called. Manual reset events are useful when one thread must complete an activity before other threads can proceed.
Automatic reset events provide exclusive access to a resource. If an automatic reset event is signaled when no threads are waiting, it remains signaled until a thread attempts to wait on it. The event releases the thread and immediately resets, blocking subsequent threads.
(Source: http://msdn.microsoft.com/en-us/library/system.threading.eventwaithandle.aspx)
For your purpose, the AutoResetEvent
should fit.
Further Explenation:
In your example, it waits for the first Set()
, then the gate is open and all the following WaitOne()
can just pass as nobody closes the gate.