EventWaitHandle Class
Represents a thread synchronization event.
System.MarshalByRefObject
System.Threading.WaitHandle
System.Threading.EventWaitHandle
System.Threading.AutoResetEvent
System.Threading.ManualResetEvent
Assembly: mscorlib (in mscorlib.dll)
The EventWaitHandle type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() ![]() ![]() | EventWaitHandle(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. |
![]() ![]() ![]() | EventWaitHandle(Boolean, EventResetMode, String) | Initializes a new instance of the EventWaitHandle class, specifying whether the wait handle is initially signaled if created as a result of this call, whether it resets automatically or manually, and the name of a system synchronization event. |
![]() ![]() ![]() | EventWaitHandle(Boolean, EventResetMode, String, Boolean) | Initializes a new instance of the EventWaitHandle class, specifying whether the wait handle is initially signaled if created as a result of this call, whether it resets automatically or manually, the name of a system synchronization event, and a Boolean variable whose value after the call indicates whether the named system event was created. |
![]() | EventWaitHandle(Boolean, EventResetMode, String, Boolean, EventWaitHandleSecurity) | Initializes a new instance of the EventWaitHandle class, specifying whether the wait handle is initially signaled if created as a result of this call, whether it resets automatically or manually, the name of a system synchronization event, a Boolean variable whose value after the call indicates whether the named system event was created, and the access control security to be applied to the named event if it is created. |
| Name | Description | |
|---|---|---|
![]() ![]() | Handle | Obsolete. Gets or sets the native operating system handle. (Inherited from WaitHandle.) |
![]() | SafeWaitHandle | Gets or sets the native operating system handle. (Inherited from WaitHandle.) |
| Name | Description | |
|---|---|---|
![]() ![]() | Close | When overridden in a derived class, releases all resources held by the current WaitHandle. (Inherited from WaitHandle.) In XNA Framework, this member is overridden by Close(). |
![]() | CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.) |
![]() ![]() ![]() | Dispose() | Releases all resources used by the current instance of the WaitHandle class. (Inherited from WaitHandle.) |
![]() ![]() ![]() ![]() | Dispose(Boolean) | When overridden in a derived class, releases the unmanaged resources used by the WaitHandle, and optionally releases the managed resources. (Inherited from WaitHandle.) |
![]() ![]() ![]() ![]() | Equals(Object) | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) In XNA Framework, this member is overridden by Finalize(). |
![]() | GetAccessControl | Gets an EventWaitHandleSecurity object that represents the access control security for the named system event represented by the current EventWaitHandle object. |
![]() ![]() ![]() ![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() ![]() ![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() ![]() ![]() ![]() | MemberwiseClone() | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.) |
![]() ![]() ![]() ![]() | OpenExisting(String) | Opens the specified named synchronization event, if it already exists. |
![]() ![]() | OpenExisting(String, EventWaitHandleRights) | Opens the specified named synchronization event, if it already exists, with the desired security access. |
![]() ![]() ![]() ![]() | Reset | Sets the state of the event to nonsignaled, causing threads to block. |
![]() ![]() ![]() ![]() | Set | Sets the state of the event to signaled, allowing one or more waiting threads to proceed. |
![]() | SetAccessControl | Sets the access control security for a named system event. |
![]() ![]() ![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() ![]() ![]() | TryOpenExisting(String, EventWaitHandle) | Opens the specified named synchronization event, if it already exists, and returns a value that indicates whether the operation succeeded. |
![]() ![]() | TryOpenExisting(String, EventWaitHandleRights, EventWaitHandle) | Opens the specified named synchronization event, if it already exists, with the desired security access, and returns a value that indicates whether the operation succeeded. |
![]() ![]() | WaitOne() | Blocks the current thread until the current WaitHandle receives a signal. (Inherited from WaitHandle.) In XNA Framework, this member is overridden by WaitOne(). |
![]() ![]() ![]() | WaitOne(Int32) | Blocks the current thread until the current WaitHandle receives a signal, using a 32-bit signed integer to specify the time interval. (Inherited from WaitHandle.) |
![]() ![]() ![]() | WaitOne(TimeSpan) | Blocks the current thread until the current instance receives a signal, using a TimeSpan to specify the time interval. (Inherited from WaitHandle.) |
![]() ![]() | WaitOne(Int32, Boolean) | Blocks the current thread until the current WaitHandle receives a signal, using a 32-bit signed integer to specify the time interval and specifying whether to exit the synchronization domain before the wait. (Inherited from WaitHandle.) In XNA Framework, this member is overridden by WaitOne(Int32, Boolean). |
![]() | WaitOne(TimeSpan, Boolean) | Blocks the current thread until the current instance receives a signal, using a TimeSpan to specify the time interval and specifying whether to exit the synchronization domain before the wait. (Inherited from WaitHandle.) |
| Name | Description | |
|---|---|---|
![]() ![]() ![]() | IDisposable.Dispose | Infrastructure. Releases all resources used by the WaitHandle. (Inherited from WaitHandle.) |
The EventWaitHandle class allows threads to communicate with each other by signaling. Typically, one or more threads block on an EventWaitHandle until an unblocked thread calls the Set method, releasing one or more of the blocked threads. A thread can signal an EventWaitHandle and then block on it, by calling the static (Shared in Visual Basic) WaitHandle.SignalAndWait method.
Note |
|---|
The EventWaitHandle class provides access to named system synchronization events. |
The behavior of an EventWaitHandle that has been signaled depends on its reset mode. An EventWaitHandle created with the EventResetMode.AutoReset flag resets automatically when signaled, after releasing a single waiting thread. An EventWaitHandle created with the EventResetMode.ManualReset flag remains signaled until its Reset method is called.
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.
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.
EventWaitHandle objects can be used with the static (Shared in Visual Basic) WaitHandle.WaitAll and WaitHandle.WaitAny methods.
For more information about thread synchronization mechanisms, see EventWaitHandle, AutoResetEvent, CountdownEvent, ManualResetEvent.
Note |
|---|
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Synchronization | ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes. |
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 the ENTER key. The example then queues another five threads and releases them all using an EventWaitHandle created with the EventResetMode.ManualReset flag.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.png?cs-save-lang=1&cs-lang=fsharp)
.png?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
Note