System.Threading.AutoResetEvent Class

Assembly: Mscorlib.dll
Namespace: System.Threading
Summary
Notifies one or more waiting threads that an event has occurred. This class cannot be inherited.
C# Syntax:
public sealed class AutoResetEvent : WaitHandle
Remarks
AutoResetEvent remains signaled until a single waiting thread is released, at which time the system automatically sets the state to nonsignaled. If no threads are waiting, the state remains signaled. For more information about handling events, see .
See also:
System.Threading Namespace | WaitHandle

System.Threading.AutoResetEvent Member List:

Public Constructors
ctor #1 Initializes a new instance of the AutoResetEvent class with a Boolean value indicating whether to set the initial state to signaled.
Public Properties
Handle
(inherited from System.Threading.WaitHandle)
Read-write

See base class member description: System.Threading.WaitHandle.Handle


Gets or sets the native operating system handle.
Public Methods
Close
(inherited from System.Threading.WaitHandle)
See base class member description: System.Threading.WaitHandle.Close


When overridden in a derived class, releases all resources held by the current WaitHandle.
CreateObjRef
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.CreateObjRef


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.GetLifetimeService


Retrieves the current lifetime service object that controls the lifetime policy for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
InitializeLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.InitializeLifetimeService


Obtains a lifetime service object to control the lifetime policy for this instance.
Reset Sets the state of the specified event to nonsignaled.
Set Sets the state of the specified event to signaled.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
WaitOne
(inherited from System.Threading.WaitHandle)
Overloaded:
WaitOne()

See base class member description: System.Threading.WaitHandle.WaitOne


When overridden in a derived class, blocks the current thread until the current WaitHandle receives a signal.
WaitOne
(inherited from System.Threading.WaitHandle)
Overloaded:
WaitOne(int millisecondsTimeout, bool exitContext)

See base class member description: System.Threading.WaitHandle.WaitOne


When overridden in a derived class, blocks the current thread until the current WaitHandle receives a signal, using 32-bit signed integer to measure the time interval and specifying whether to exit the synchronization domain before the wait.
WaitOne
(inherited from System.Threading.WaitHandle)
Overloaded:
WaitOne(TimeSpan timeout, bool exitContext)

See base class member description: System.Threading.WaitHandle.WaitOne


When overridden in a derived class, blocks the current thread until the current instance receives a signal, using a TimeSpan to measure the time interval and specifying whether to exit the synchronization domain before the wait.
Protected Methods
Dispose
(inherited from System.Threading.WaitHandle)
See base class member description: System.Threading.WaitHandle.Dispose


When overridden in a derived class, releases the unmanaged resources used by the WaitHandle, and optionally releases the managed resources.
Finalize
(inherited from System.Threading.WaitHandle)
See base class member description: System.Threading.WaitHandle.Finalize


Releases the resources held by the current instance.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Threading.AutoResetEvent Member Details

ctor #1
Summary
Initializes a new instance of the AutoResetEvent class with a Boolean value indicating whether to set the initial state to signaled.
C# Syntax:
public AutoResetEvent(
   bool initialState
);
Parameters:

initialState

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

Return to top


Property: Handle (read-write)
Inherited
See base class member description: System.Threading.WaitHandle.Handle

Summary
Gets or sets the native operating system handle.
C# Syntax:
public virtual IntPtr Handle {get; set;}
Exceptions
Exception Type Condition
SecurityException The caller does not have the required permission.
.NET Framework Security:
SecurityPermissionAttribute for access to unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: Close()
Inherited
See base class member description: System.Threading.WaitHandle.Close

Summary
When overridden in a derived class, releases all resources held by the current WaitHandle.
C# Syntax:
public virtual void Close();
Remarks
This method is the public version of the IDisposable.Dispose method implemented to support the IDisposable interface.

This method releases any unmanaged resources held by the current instance. This method can, but is not required to, suppress finalization during garbage collection by calling the GC.SuppressFinalize method.

Override this method to release resources allocated in derived classes.

Use this method to release all resources held by an instance of WaitHandle. Once this method is called, references to the current instance cause undefined behavior.

Return to top


Method: CreateObjRef(
   Type requestedType
)
Inherited
See base class member description: System.MarshalByRefObject.CreateObjRef

Summary
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
C# Syntax:
public virtual ObjRef CreateObjRef(
   Type requestedType
);
Parameters:

requestedType

The Type of the object that the new ObjRef will reference.

Return Value:
Information required to generate a proxy.
Exceptions
Exception Type Condition
RemotingException This instance is not a valid remoting object.

Return to top


Method: Dispose(
   bool explicitDisposing
)
Inherited
See base class member description: System.Threading.WaitHandle.Dispose

Summary
When overridden in a derived class, releases the unmanaged resources used by the WaitHandle, and optionally releases the managed resources.
C# Syntax:
protected virtual void Dispose(
   bool explicitDisposing
);
Parameters:

explicitDisposing

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks
This method is called by the WaitHandle.Dispose() method and the Finalize method.Dispose() invokes this protected method with the explicitDisposing parameter set to true.Finalize invokes Dispose with explicitDisposing set to false.

When the explicitDisposing parameter is true, this method releases all resources held by any managed objects that this WaitHandle references. This method invokes the Dispose() method of each referenced object.

Dispose can be called multiple times by other objects. When overriding this method, be careful not to reference objects that have been previously disposed in an earlier call to Dispose or Close.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Threading.WaitHandle.Finalize

Summary
Releases the resources held by the current instance.
C# Syntax:
~WaitHandle();
Remarks
Application code does not call this method; it is automatically invoked during garbage collection, unless finalization by the garbage collector has been disabled. For more information, see GC.SuppressFinalize and Object.Finalize. This method overrides System.Object.Finalize.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.GetLifetimeService

Summary
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
C# Syntax:
public object GetLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance.
Remarks
For more information about lifetime services, see the LifetimeServices class.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: InitializeLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.InitializeLifetimeService

Summary
Obtains a lifetime service object to control the lifetime policy for this instance.
C# Syntax:
public virtual object InitializeLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the LifetimeServices.LeaseManagerPollTime property.
Remarks
For more information about lifetime services, see the LifetimeServices class.
Example
The following code example demonstrates creating a lease.
 public class MyClass : MarshalByRefObject
 {
   public override Object InitializeLifetimeService()
   {
     ILease lease = (ILease)base.InitializeLifetimeService();
     if (lease.CurrentState == LeaseState.Initial)
     {
          lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
          lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
           lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
     }
       return lease;
   }
 }

    

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Reset()
Summary
Sets the state of the specified event to nonsignaled.
C# Syntax:
public bool Reset();
Return Value:
true if the function succeeds; otherwise, false.

Return to top


Method: Set()
Summary
Sets the state of the specified event to signaled.
C# Syntax:
public bool Set();
Return Value:
true if the function succeeds; otherwise, false.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: WaitOne()
Inherited
See base class member description: System.Threading.WaitHandle.WaitOne

Summary
When overridden in a derived class, blocks the current thread until the current WaitHandle receives a signal.
C# Syntax:
public virtual bool WaitOne();
Return Value:
true if the current instance receives a signal; otherwise, false.
Remarks
The caller of this method blocks indefinitely until the current instance receives a signal. Use this method to block until a WaitHandle receives a signal from another thread, such as is generated when an asynchronous operation completes. For more information, see the System.IAsyncResult interface.

Override this method to customize the behavior of derived classes.

Return to top


Overloaded Method: WaitOne(
   int millisecondsTimeout,
   bool exitContext
)
Inherited
See base class member description: System.Threading.WaitHandle.WaitOne

Summary
When overridden in a derived class, blocks the current thread until the current WaitHandle receives a signal, using 32-bit signed integer to measure the time interval and specifying whether to exit the synchronization domain before the wait.
C# Syntax:
public virtual bool WaitOne(
   int millisecondsTimeout,
   bool exitContext
);
Parameters:

millisecondsTimeout

The number of milliseconds to wait for the thread to receive a signal.

exitContext

true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false.

Return Value:
true if the current instance receives a signal; otherwise, false.
Remarks
The caller of this method blocks indefinitely until the current instance receives a signal. Use this method to block until a WaitHandle receives a signal from another thread, such as is generated when an asynchronous operation completes. For more information, see the System.IAsyncResult interface.

Override this method to customize the behavior of derived classes.

Return to top


Overloaded Method: WaitOne(
   TimeSpan timeout,
   bool exitContext
)
Inherited
See base class member description: System.Threading.WaitHandle.WaitOne

Summary
When overridden in a derived class, blocks the current thread until the current instance receives a signal, using a TimeSpan to measure the time interval and specifying whether to exit the synchronization domain before the wait.
C# Syntax:
public virtual bool WaitOne(
   TimeSpan timeout,
   bool exitContext
);
Parameters:

timeout

The number of milliseconds to wait for the thread to receive a signal.

exitContext

true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false.

Return Value:
true if the current instance receives a signal; otherwise, false.
Remarks
The caller of this method blocks indefinitely until the current instance receives a signal. Use this method to block until a WaitHandle receives a signal from another thread, such as is generated when an asynchronous operation completes. For more information, see the System.IAsyncResult interface.

Override this method to customize the behavior of derived classes.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.