See Also: AutoResetEvent Members
AutoResetEvent allows threads to communicate with each other by signaling. Typically, you use this class when threads need exclusive access to a resource.
A thread waits for a signal by calling WaitHandle.WaitOne(int, bool) on the AutoResetEvent. If the AutoResetEvent is in the non-signaled state, the thread blocks, waiting for the thread that currently controls the resource to signal that the resource is available by calling EventWaitHandle.Set.
Calling Set signals AutoResetEvent to release a waiting thread. AutoResetEvent remains signaled until a single waiting thread is released, and then automatically returns to the non-signaled state. If no threads are waiting, the state remains signaled indefinitely.
If a thread calls WaitHandle.WaitOne(int, bool) while the System.Threading.AutoResetEvent is in the signaled state, the thread does not block. The System.Threading.AutoResetEvent releases the thread immediately and returns to the non-signaled state.
There is no guarantee that every call to the EventWaitHandle.Set method will release a thread. If two calls are too close together, so that the second call occurs before a thread has been released, only one thread is released. It is as if the second call did not happen. Also, if EventWaitHandle.Set is called when there are no threads waiting and the System.Threading.AutoResetEvent is already signaled, the call has no effect.
You can control the initial state of an AutoResetEvent by passing a Boolean value to the constructor: true if the initial state is signaled and false otherwise.
For more information about thread synchronization mechanisms, see AutoResetEvent in the conceptual documentation.
Beginning with the .NET Framework version 2.0, System.Threading.AutoResetEvent derives from the new System.Threading.EventWaitHandle class. An System.Threading.AutoResetEvent is functionally equivalent to an System.Threading.EventWaitHandle created with EventResetMode.AutoReset.