Export (0) Print
Expand All

Mutex.TryOpenExisting Method (String, MutexRights, Mutex)

.NET Framework 4.5

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

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public static bool TryOpenExisting(
	string name,
	MutexRights rights,
	out Mutex result
)

Parameters

name
Type: System.String

The name of the system mutex to open.

rights
Type: System.Security.AccessControl.MutexRights

A bitwise combination of the enumeration values that represent the desired security access.

result
Type: System.Threading.Mutex

When this method returns, contains a Mutex object that represents the named mutex if the call succeeded, or null if the call failed. This parameter is treated as uninitialized.

Return Value

Type: System.Boolean
true if the named mutex was opened successfully; otherwise, false.

ExceptionCondition
ArgumentException

name is an empty string.

-or-

name is longer than 260 characters.

ArgumentNullException

name is null.

IOException

A Win32 error occurred.

UnauthorizedAccessException

The named mutex exists, but the user does not have the security access required to use it.

If the named mutex does not exist, this method does not create it. To create the system mutex when it does not already exist, use one of the Mutex constructors that has a name parameter.

If you are uncertain whether a named mutex exists, use this method overload instead of the OpenExisting(String, MutexRights) method overload, which throws an exception if the mutex does not exist.

The rights parameter must include the MutexRights.Synchronize flag to allow threads to wait on the mutex, and the MutexRights.Modify flag to allow threads to call the ReleaseMutex method.

Multiple calls to this method that use the same value for name do not necessarily return the same Mutex object, even though the objects that are returned represent the same named system mutex.

This method does not request ownership of the mutex.

.NET Framework

Supported in: 4.6, 4.5

  • SecurityCriticalAttribute 

    requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Windows 8.1, Windows Server 2012 R2, 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.

Show:
© 2014 Microsoft