Mutex.ReleaseMutex Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Releases the Mutex once.

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Sub ReleaseMutex
[SecuritySafeCriticalAttribute]
public void ReleaseMutex()

Exceptions

Exception Condition
ApplicationException

The calling thread does not own the mutex.

Remarks

A thread that owns a mutex can specify the same mutex in repeated wait function calls without blocking its execution. The number of calls is kept by the common language runtime. The thread must call ReleaseMutex the same number of times to release ownership of the mutex.

If a thread terminates while owning a mutex, the mutex is said to be abandoned. The state of the mutex is set to signaled and the next waiting thread gets ownership. Typically, if no one owns the mutex, the state of the mutex is signaled and an AbandonedMutexException is thrown in the next thread that acquires the mutex. Silverlight for Windows Phone In Silverlight for Windows Phone, an AbandonedMutexException is not thrown.

Caution noteCaution:

An abandoned mutex often indicates a serious error in the code. When a thread exits without releasing the mutex, the data structures protected by the mutex might not be in a consistent state. The next thread to request ownership of the mutex can handle this exception and proceed, if the integrity of the data structures can be verified.

In the case of a system-wide mutex, an abandoned mutex might indicate that an application has been terminated abruptly (for example, by using Windows Task Manager).

Version Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 In Silverlight for Windows Phone, AbandonedMutexException is not thrown when a mutex is abandoned.

Version Information

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.