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

The caller of this method blocks until the current instance receives a signal or a time-out occurs. Use this method to block until a WaitHandle receives a signal from another thread, such as the signal that is generated when an asynchronous operation completes. For more information, see the IAsyncResult interface.

The following example shows how to use the WaitOne(Int32) method overload to enable the waiting thread to break out of a long wait and do some processing.

The example queues three tasks by using the ThreadPool.QueueUserWorkItem method. Each task calls WaitOne on a common AutoResetEvent, using a three-second time-out. If the wait times out, the task displays a message and resumes waiting. You could add code here to abandon the wait depending on conditions.

The example releases a waiting thread each time the MouseLeftButtonUp event occurs. When the last thread is released, it unhooks the event handler and displays a final message. The Interlocked.Increment and Interlocked.Decrement methods are used to ensure that the count is protected from concurrent access.