AutoResetEvent Class
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Notifies a waiting thread that an event has occurred. This class cannot be inherited.
Inheritance Hierarchy
System. . :: . .Object
System. . :: . .MarshalByRefObject
System.Threading. . :: . .WaitHandle
System.Threading..::..AutoResetEvent
Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public NotInheritable Class AutoResetEvent _
Inherits WaitHandle
public sealed class AutoResetEvent : WaitHandle
public ref class AutoResetEvent sealed : public WaitHandle
[<Sealed>]
type AutoResetEvent =
class
inherit WaitHandle
end
public final class AutoResetEvent extends WaitHandle
The AutoResetEvent type exposes the following members.
Constructors
Name | Description | |
---|---|---|
AutoResetEvent | Initializes a new instance of the AutoResetEvent class with a Boolean value indicating whether to set the initial state to signaled. |
Top
Methods
Name | Description | |
---|---|---|
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Reset | Sets the state of the event to nonsignaled, which causes threads to block. | |
Set | Sets the state of the event to signaled, which allows at most one waiting thread to proceed. | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
WaitOne() () () () | Blocks the current thread until the current WaitHandle receives a signal. (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.) |
Top
Remarks
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 WaitOne 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 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 WaitOne while the AutoResetEvent is in the signaled state, the thread does not block. The AutoResetEvent releases the thread immediately and returns to the non-signaled state.
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.
AutoResetEvent can also be used with the staticWaitAll and WaitAny methods.
Note
Unlike the AutoResetEvent class, the EventWaitHandle class provides access to named system synchronization events.
Thread Safety
This class is thread safe.