Mutex.OpenExisting Method (String)
Opens the specified named mutex, if it already exists.
Assemblies: mscorlib (in mscorlib.dll)
System.Threading (in System.Threading.dll)
name is an empty string.
name is longer than 260 characters.
name is a null reference (Nothing in Visual Basic).
The named mutex does not exist.
A Win32 error occurred.
The named mutex exists, but the user does not have the security access required to use it.
The OpenExisting method tries to open the specified named system mutex. If the system mutex does not exist, this method throws an exception instead of creating the system object. To create the system mutex when it does not already exist, use one of the Mutex constructors that has a name parameter.
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 overload is equivalent to calling the OpenExisting(String, MutexRights) method overload and specifying MutexRights.Synchronize and MutexRights.Modify rights, combined by using the bitwise OR operation.
This method does not request ownership of the mutex.
The following code example demonstrates the cross-process behavior of a named mutex with access control security. The example uses the method overload to test for the existence of a named mutex.
If the mutex does not exist, it is created with initial ownership and access control security that denies the current user the right to use the mutex, but grants the right to read and change permissions on the mutex.
If you run the compiled example from two command windows, the second copy will throw an access violation exception on the call to . The exception is caught, and the example uses the OpenExisting(String, MutexRights) method overload to open the mutex with the rights needed to read and change the permissions.
After the permissions are changed, the mutex is opened with the rights required to enter and release it. If you run the compiled example from a third command window, it runs using the new permissions.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8
Requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Windows Phone 8.1, Windows Phone 8, 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.