Exit Method
Collapse the table of content
Expand the table of content

Monitor.Exit Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Releases an exclusive lock on the specified object.

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

public static void Exit(
	Object obj


Type: System.Object
The object on which to release the lock.


The obj parameter is null.


The 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 Enter 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 Pulse or PulseAll before invoking Exit.

The following example demonstrates how to use the Exit method. This code is part of a larger example provided for the Enter method.

// A queue that is protected by Monitor.
private Queue<T> m_inputQueue = new Queue<T>();

// Lock the queue and add an element.
public void Enqueue(T qValue)
   // Request the lock, and block until it is obtained.
      // When the lock is obtained, add an element.
      // Ensure that the lock is released.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft