EventWaitHandle Constructor (Boolean, EventResetMode)

 

Initializes a new instance of the EventWaitHandle class, specifying whether the wait handle is initially signaled, and whether it resets automatically or manually.

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

new : 
        initialState:bool *
        mode:EventResetMode -> EventWaitHandle

Parameters

initialState
Type: System.Boolean

true to set the initial state to signaled; false to set it to nonsignaled.

mode
Type: System.Threading.EventResetMode

One of the EventResetMode values that determines whether the event resets automatically or manually.

If the initial state of the event is nonsignaled, threads that wait on the event will block. If the initial state is signaled, and the ManualReset flag is specified for mode, threads that wait on the event will not block. If the initial state is signaled, and mode is AutoReset, the first thread that waits on the event will be released immediately, after which the event will reset, and subsequent threads will block.

The following code example uses the SignalAndWait(WaitHandle, WaitHandle) method overload to allow the main thread to signal a blocked thread and then wait until the thread finishes a task.

The example starts five threads and allows them to block on an EventWaitHandle created with the EventResetMode.AutoReset flag, then releases one thread each time the user presses ENTER key. The example then queues another five threads and releases them all using an EventWaitHandle created with the EventResetMode.ManualReset flag.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show: