System.Threading.Monitor.Exit Method

Releases an exclusive lock on the specified object.


[System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)]
public static void Exit (object obj)


The object on which to release the lock.


ArgumentNullException obj is null.
System.Threading.SynchronizationLockExceptionThe current thread does not own the lock for the specified object.


The calling thread must own the lock on the obj parameter. If the calling thread owns the lock on the specified object, and has made an equal number of Exit and Monitor.Enter(object) calls for the object, then the lock is released. If the calling thread has not invoked Exit as many times as Enter, the lock is not released.

If the lock is released and other threads are in the ready queue for the object, one of the threads acquires the lock. If other threads are in the waiting queue waiting to acquire the lock, they are not automatically moved to the ready queue when the owner of the lock calls Exit. To move one or more waiting threads into the ready queue, call Monitor.Pulse(object) or Monitor.PulseAll(object) before invoking Exit.


Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0,,