public sealed class Mutex : WaitHandle
|
You can use WaitHandle.WaitOne to request ownership of a mutex. The thread that owns a mutex can request the same mutex in repeated calls to Wait without blocking its execution. However, the thread must call the Mutex.ReleaseMutex method the same number of times to release ownership of the mutex. If a thread terminates normally while owning a mutex, the state of the mutex is set to signaled and the next waiting thread gets ownership. If no one owns the mutex, the state of the mutex is signaled.
ctor #1 | Overloaded:.ctor() Default constructor. This constructor is called by derived class constructors to initialize state in this type.Initializes a new instance of the Mutex class with default properties. |
ctor #2 | Overloaded:.ctor(bool initiallyOwned) Initializes a new instance of the Mutex class with a Boolean value indicating whether the calling thread should have initial ownership of the mutex. |
ctor #3 | Overloaded:.ctor(bool initiallyOwned, string name) Initializes a new instance of the Mutex class with a Boolean value indicating whether the calling thread should have initial ownership of the mutex, and a string that is the name of the mutex. |
ctor #4 | Overloaded:.ctor(bool initiallyOwned, string name, out bool createdNew) Initializes a new instance of the Mutex class with a Boolean value indicating whether the calling thread should have initial ownership of the mutex, a string that is the name of the mutex, and a Boolean value that, when the method returns, will indicate whether the calling thread was granted initial ownership of the mutex. |
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. |
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. |
ReleaseMutex | Releases the Mutex once. |
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.WaitOneWhen 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.WaitOneWhen 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.WaitOneWhen 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. |
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:
public Mutex(); |
public Mutex( |
initiallyOwned
initiallyOwned
name
initiallyOwned
name
createdNew
public virtual IntPtr Handle {get; set;}
|
Exception Type | Condition |
---|---|
SecurityException | The caller does not have the required permission. |
public virtual void Close(); |
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.
requestedType
Exception Type | Condition |
---|---|
RemotingException | This instance is not a valid remoting object. |
protected virtual void Dispose( |
explicitDisposing
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.
~WaitHandle(); |
public virtual int GetHashCode(); |
public object GetLifetimeService(); |
public Type GetType(); |
public virtual object InitializeLifetimeService(); |
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; } }
protected object MemberwiseClone(); |
public void ReleaseMutex(); |
Exception Type | Condition |
---|---|
ApplicationException | The calling thread does not own the mutex. |
public virtual string ToString(); |
public virtual bool WaitOne(); |
Override this method to customize the behavior of derived classes.
millisecondsTimeout
exitContext
Override this method to customize the behavior of derived classes.
timeout
exitContext
Override this method to customize the behavior of derived classes.