mscorlib(4.0.0.0) API with additions
System.Threading.Mutex Class Reference

A synchronization primitive that can also be used for interprocess synchronization. More...

Inheritance diagram for System.Threading.Mutex:
[legend]
Collaboration diagram for System.Threading.Mutex:
[legend]

Public Member Functions

 Mutex (bool initiallyOwned, string name, out bool createdNew)
 Initializes a new instance of the T:System.Threading.Mutex class with a Boolean value that indicates 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, indicates whether the calling thread was granted initial ownership of the mutex. More...
 
unsafe Mutex (bool initiallyOwned, string name, out bool createdNew, MutexSecurity mutexSecurity)
 Initializes a new instance of the T:System.Threading.Mutex class with a Boolean value that indicates whether the calling thread should have initial ownership of the mutex, a string that is the name of the mutex, a Boolean variable that, when the method returns, indicates whether the calling thread was granted initial ownership of the mutex, and the access control security to be applied to the named mutex. More...
 
 Mutex (bool initiallyOwned, string name)
 Initializes a new instance of the T:System.Threading.Mutex class with a Boolean value that indicates whether the calling thread should have initial ownership of the mutex, and a string that is the name of the mutex. More...
 
 Mutex (bool initiallyOwned)
 Initializes a new instance of the T:System.Threading.Mutex class with a Boolean value that indicates whether the calling thread should have initial ownership of the mutex. More...
 
 Mutex ()
 Initializes a new instance of the T:System.Threading.Mutex class with default properties. More...
 
void ReleaseMutex ()
 Releases the T:System.Threading.Mutex once. More...
 
MutexSecurity GetAccessControl ()
 Gets a T:System.Security.AccessControl.MutexSecurity object that represents the access control security for the named mutex. More...
 
void SetAccessControl (MutexSecurity mutexSecurity)
 Sets the access control security for a named system mutex. More...
 
- Public Member Functions inherited from System.Threading.WaitHandle
virtual bool WaitOne (int millisecondsTimeout, bool exitContext)
 Blocks the current thread until the current T:System.Threading.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. More...
 
virtual bool WaitOne (TimeSpan timeout, bool exitContext)
 Blocks the current thread until the current instance receives a signal, using a T:System.TimeSpan to specify the time interval and specifying whether to exit the synchronization domain before the wait. More...
 
virtual bool WaitOne ()
 Blocks the current thread until the current T:System.Threading.WaitHandle receives a signal. More...
 
virtual bool WaitOne (int millisecondsTimeout)
 Blocks the current thread until the current T:System.Threading.WaitHandle receives a signal, using a 32-bit signed integer to specify the time interval in milliseconds. More...
 
virtual bool WaitOne (TimeSpan timeout)
 Blocks the current thread until the current instance receives a signal, using a T:System.TimeSpan to specify the time interval. More...
 
virtual void Close ()
 Releases all resources held by the current T:System.Threading.WaitHandle. More...
 
void Dispose ()
 Releases all resources used by the current instance of the T:System.Threading.WaitHandle class. More...
 
- Public Member Functions inherited from System.MarshalByRefObject
object GetLifetimeService ()
 Retrieves the current lifetime service object that controls the lifetime policy for this instance. More...
 
virtual object InitializeLifetimeService ()
 Obtains a lifetime service object to control the lifetime policy for this instance. More...
 
virtual ObjRef CreateObjRef (Type requestedType)
 Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. More...
 

Static Public Member Functions

static Mutex OpenExisting (string name)
 Opens the specified named mutex, if it already exists. More...
 
static Mutex OpenExisting (string name, MutexRights rights)
 Opens the specified named mutex, if it already exists, with the desired security access. More...
 
static bool TryOpenExisting (string name, out Mutex result)
 Opens the specified named mutex, if it already exists, and returns a value that indicates whether the operation succeeded. More...
 
static bool TryOpenExisting (string name, MutexRights rights, out Mutex result)
 Opens the specified named mutex, if it already exists, with the desired security access, and returns a value that indicates whether the operation succeeded. More...
 
- Static Public Member Functions inherited from System.Threading.WaitHandle
static bool WaitAll (WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext)
 Waits for all the elements in the specified array to receive a signal, using an T:System.Int32 value to specify the time interval and specifying whether to exit the synchronization domain before the wait. More...
 
static bool WaitAll (WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext)
 Waits for all the elements in the specified array to receive a signal, using a T:System.TimeSpan value to specify the time interval, and specifying whether to exit the synchronization domain before the wait. More...
 
static bool WaitAll (WaitHandle[] waitHandles)
 Waits for all the elements in the specified array to receive a signal. More...
 
static bool WaitAll (WaitHandle[] waitHandles, int millisecondsTimeout)
 Waits for all the elements in the specified array to receive a signal, using an T:System.Int32 value to specify the time interval. More...
 
static bool WaitAll (WaitHandle[] waitHandles, TimeSpan timeout)
 Waits for all the elements in the specified array to receive a signal, using a T:System.TimeSpan value to specify the time interval. More...
 
static int WaitAny (WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext)
 Waits for any of the elements in the specified array to receive a signal, using a 32-bit signed integer to specify the time interval, and specifying whether to exit the synchronization domain before the wait. More...
 
static int WaitAny (WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext)
 Waits for any of the elements in the specified array to receive a signal, using a T:System.TimeSpan to specify the time interval and specifying whether to exit the synchronization domain before the wait. More...
 
static int WaitAny (WaitHandle[] waitHandles, TimeSpan timeout)
 Waits for any of the elements in the specified array to receive a signal, using a T:System.TimeSpan to specify the time interval. More...
 
static int WaitAny (WaitHandle[] waitHandles)
 Waits for any of the elements in the specified array to receive a signal. More...
 
static int WaitAny (WaitHandle[] waitHandles, int millisecondsTimeout)
 Waits for any of the elements in the specified array to receive a signal, using a 32-bit signed integer to specify the time interval. More...
 
static bool SignalAndWait (WaitHandle toSignal, WaitHandle toWaitOn)
 Signals one T:System.Threading.WaitHandle and waits on another. More...
 
static bool SignalAndWait (WaitHandle toSignal, WaitHandle toWaitOn, TimeSpan timeout, bool exitContext)
 Signals one T:System.Threading.WaitHandle and waits on another, specifying the time-out interval as a T:System.TimeSpan and specifying whether to exit the synchronization domain for the context before entering the wait. More...
 
static bool SignalAndWait (WaitHandle toSignal, WaitHandle toWaitOn, int millisecondsTimeout, bool exitContext)
 Signals one T:System.Threading.WaitHandle and waits on another, specifying a time-out interval as a 32-bit signed integer and specifying whether to exit the synchronization domain for the context before entering the wait. More...
 

Additional Inherited Members

- Public Attributes inherited from System.Threading.WaitHandle
const int WaitTimeout = 258
 Indicates that a M:System.Threading.WaitHandle.WaitAny(System.Threading.WaitHandle[],System.Int32,System.Boolean) operation timed out before any of the wait handles were signaled. This field is constant. More...
 
- Protected Member Functions inherited from System.Threading.WaitHandle
 WaitHandle ()
 Initializes a new instance of the T:System.Threading.WaitHandle class. More...
 
virtual void Dispose (bool explicitDisposing)
 When overridden in a derived class, releases the unmanaged resources used by the T:System.Threading.WaitHandle, and optionally releases the managed resources. More...
 
- Protected Member Functions inherited from System.MarshalByRefObject
MarshalByRefObject MemberwiseClone (bool cloneIdentity)
 Creates a shallow copy of the current T:System.MarshalByRefObject object. More...
 
- Static Protected Attributes inherited from System.Threading.WaitHandle
static readonly IntPtr InvalidHandle = GetInvalidHandle()
 Represents an invalid native operating system handle. This field is read-only. More...
 
- Properties inherited from System.Threading.WaitHandle
virtual IntPtr Handle [get, set]
 Gets or sets the native operating system handle. More...
 
SafeWaitHandle SafeWaitHandle [get, set]
 Gets or sets the native operating system handle. More...
 

Detailed Description

A synchronization primitive that can also be used for interprocess synchronization.

Definition at line 17 of file Mutex.cs.

Constructor & Destructor Documentation

◆ Mutex() [1/5]

System.Threading.Mutex.Mutex ( bool  initiallyOwned,
string  name,
out bool  createdNew 
)

Initializes a new instance of the T:System.Threading.Mutex class with a Boolean value that indicates 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, indicates whether the calling thread was granted initial ownership of the mutex.

Parameters
initiallyOwnedtrue to give the calling thread initial ownership of the named system mutex if the named system mutex is created as a result of this call; otherwise, false.
nameThe name of the T:System.Threading.Mutex. If the value is null, the T:System.Threading.Mutex is unnamed.
createdNewWhen this method returns, contains a Boolean that is true if a local mutex was created (that is, if name is null or an empty string) or if the specified named system mutex was created; false if the specified named system mutex already existed. This parameter is passed uninitialized.
Exceptions
T:System.UnauthorizedAccessExceptionThe named mutex exists and has access control security, but the user does not have F:System.Security.AccessControl.MutexRights.FullControl.
T:System.IO.IOExceptionA Win32 error occurred.
T:System.Threading.WaitHandleCannotBeOpenedExceptionThe named mutex cannot be created, perhaps because a wait handle of a different type has the same name.
T:System.ArgumentExceptionname is longer than 260 characters.

Definition at line 117 of file Mutex.cs.

◆ Mutex() [2/5]

unsafe System.Threading.Mutex.Mutex ( bool  initiallyOwned,
string  name,
out bool  createdNew,
MutexSecurity  mutexSecurity 
)

Initializes a new instance of the T:System.Threading.Mutex class with a Boolean value that indicates whether the calling thread should have initial ownership of the mutex, a string that is the name of the mutex, a Boolean variable that, when the method returns, indicates whether the calling thread was granted initial ownership of the mutex, and the access control security to be applied to the named mutex.

Parameters
initiallyOwnedtrue to give the calling thread initial ownership of the named system mutex if the named system mutex is created as a result of this call; otherwise, false.
nameThe name of the system mutex. If the value is null, the T:System.Threading.Mutex is unnamed.
createdNewWhen this method returns, contains a Boolean that is true if a local mutex was created (that is, if name is null or an empty string) or if the specified named system mutex was created; false if the specified named system mutex already existed. This parameter is passed uninitialized.
mutexSecurityA T:System.Security.AccessControl.MutexSecurity object that represents the access control security to be applied to the named system mutex.
Exceptions
T:System.IO.IOExceptionA Win32 error occurred.
T:System.UnauthorizedAccessExceptionThe named mutex exists and has access control security, but the user does not have F:System.Security.AccessControl.MutexRights.FullControl.
T:System.Threading.WaitHandleCannotBeOpenedExceptionThe named mutex cannot be created, perhaps because a wait handle of a different type has the same name.
T:System.ArgumentExceptionname is longer than 260 characters.

Definition at line 135 of file Mutex.cs.

◆ Mutex() [3/5]

System.Threading.Mutex.Mutex ( bool  initiallyOwned,
string  name 
)

Initializes a new instance of the T:System.Threading.Mutex class with a Boolean value that indicates whether the calling thread should have initial ownership of the mutex, and a string that is the name of the mutex.

Parameters
initiallyOwnedtrue to give the calling thread initial ownership of the named system mutex if the named system mutex is created as a result of this call; otherwise, false.
nameThe name of the T:System.Threading.Mutex. If the value is null, the T:System.Threading.Mutex is unnamed.
Exceptions
T:System.UnauthorizedAccessExceptionThe named mutex exists and has access control security, but the user does not have F:System.Security.AccessControl.MutexRights.FullControl.
T:System.IO.IOExceptionA Win32 error occurred.
T:System.Threading.WaitHandleCannotBeOpenedExceptionThe named mutex cannot be created, perhaps because a wait handle of a different type has the same name.
T:System.ArgumentExceptionname is longer than 260 characters.

Definition at line 213 of file Mutex.cs.

◆ Mutex() [4/5]

System.Threading.Mutex.Mutex ( bool  initiallyOwned)

Initializes a new instance of the T:System.Threading.Mutex class with a Boolean value that indicates whether the calling thread should have initial ownership of the mutex.

Parameters
initiallyOwnedtrue to give the calling thread initial ownership of the mutex; otherwise, false.

Definition at line 224 of file Mutex.cs.

◆ Mutex() [5/5]

System.Threading.Mutex.Mutex ( )

Initializes a new instance of the T:System.Threading.Mutex class with default properties.

Definition at line 233 of file Mutex.cs.

Member Function Documentation

◆ GetAccessControl()

MutexSecurity System.Threading.Mutex.GetAccessControl ( )

Gets a T:System.Security.AccessControl.MutexSecurity object that represents the access control security for the named mutex.

Returns
A T:System.Security.AccessControl.MutexSecurity object that represents the access control security for the named mutex.
Exceptions
T:System.UnauthorizedAccessExceptionThe current T:System.Threading.Mutex object represents a named system mutex, but the user does not have F:System.Security.AccessControl.MutexRights.ReadPermissions.-or-The current T:System.Threading.Mutex object represents a named system mutex, and was not opened with F:System.Security.AccessControl.MutexRights.ReadPermissions.
T:System.NotSupportedExceptionNot supported for Windows 98 or Windows Millennium Edition.

Definition at line 440 of file Mutex.cs.

◆ OpenExisting() [1/2]

static Mutex System.Threading.Mutex.OpenExisting ( string  name)
static

Opens the specified named mutex, if it already exists.

Parameters
nameThe name of the system mutex to open.
Returns
An object that represents the named system mutex.
Exceptions
T:System.ArgumentExceptionname is an empty string.-or- name is longer than 260 characters.
T:System.ArgumentNullExceptionname is null.
T:System.Threading.WaitHandleCannotBeOpenedExceptionThe named mutex does not exist.
T:System.IO.IOExceptionA Win32 error occurred.
T:System.UnauthorizedAccessExceptionThe named mutex exists, but the user does not have the security access required to use it.

Definition at line 259 of file Mutex.cs.

◆ OpenExisting() [2/2]

static Mutex System.Threading.Mutex.OpenExisting ( string  name,
MutexRights  rights 
)
static

Opens the specified named mutex, if it already exists, with the desired security access.

Parameters
nameThe name of the system mutex to open.
rightsA bitwise combination of the enumeration values that represent the desired security access.
Returns
An object that represents the named system mutex.
Exceptions
T:System.ArgumentExceptionname is an empty string. -or- name is longer than 260 characters.
T:System.ArgumentNullExceptionname is null.
T:System.Threading.WaitHandleCannotBeOpenedExceptionThe named mutex does not exist.
T:System.IO.IOExceptionA Win32 error occurred.
T:System.UnauthorizedAccessExceptionThe named mutex exists, but the user does not have the desired security access.

Definition at line 277 of file Mutex.cs.

◆ ReleaseMutex()

void System.Threading.Mutex.ReleaseMutex ( )

Releases the T:System.Threading.Mutex once.

Exceptions
T:System.ApplicationExceptionThe calling thread does not own the mutex.
T:System.ObjectDisposedExceptionThe current instance has already been disposed.

Definition at line 377 of file Mutex.cs.

◆ SetAccessControl()

void System.Threading.Mutex.SetAccessControl ( MutexSecurity  mutexSecurity)

Sets the access control security for a named system mutex.

Parameters
mutexSecurityA T:System.Security.AccessControl.MutexSecurity object that represents the access control security to be applied to the named system mutex.
Exceptions
T:System.ArgumentNullExceptionmutexSecurity is null.
T:System.UnauthorizedAccessExceptionThe user does not have F:System.Security.AccessControl.MutexRights.ChangePermissions.-or-The mutex was not opened with F:System.Security.AccessControl.MutexRights.ChangePermissions.
T:System.SystemExceptionThe current T:System.Threading.Mutex object does not represent a named system mutex.

Definition at line 452 of file Mutex.cs.

◆ TryOpenExisting() [1/2]

static bool System.Threading.Mutex.TryOpenExisting ( string  name,
out Mutex  result 
)
static

Opens the specified named mutex, if it already exists, and returns a value that indicates whether the operation succeeded.

Parameters
nameThe name of the system mutex to open.
resultWhen this method returns, contains a T:System.Threading.Mutex object that represents the named mutex if the call succeeded, or null if the call failed. This parameter is treated as uninitialized.
Returns
true if the named mutex was opened successfully; otherwise, false.
Exceptions
T:System.ArgumentExceptionname is an empty string.-or- name is longer than 260 characters.
T:System.ArgumentNullExceptionname is null.
T:System.IO.IOExceptionA Win32 error occurred.
T:System.UnauthorizedAccessExceptionThe named mutex exists, but the user does not have the security access required to use it.

Definition at line 308 of file Mutex.cs.

◆ TryOpenExisting() [2/2]

static bool System.Threading.Mutex.TryOpenExisting ( string  name,
MutexRights  rights,
out Mutex  result 
)
static

Opens the specified named mutex, if it already exists, with the desired security access, and returns a value that indicates whether the operation succeeded.

Parameters
nameThe name of the system mutex to open.
rightsA bitwise combination of the enumeration values that represent the desired security access.
resultWhen this method returns, contains a T:System.Threading.Mutex object that represents the named mutex if the call succeeded, or null if the call failed. This parameter is treated as uninitialized.
Returns
true if the named mutex was opened successfully; otherwise, false.
Exceptions
T:System.ArgumentExceptionname is an empty string.-or- name is longer than 260 characters.
T:System.ArgumentNullExceptionname is null.
T:System.IO.IOExceptionA Win32 error occurred.
T:System.UnauthorizedAccessExceptionThe named mutex exists, but the user does not have the security access required to use it.

Definition at line 327 of file Mutex.cs.


The documentation for this class was generated from the following file: