IsEntered Method
Collapse the table of content
Expand the table of content

Monitor.IsEntered Method

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

Determines whether the current thread holds a lock on the specified object.

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

'Declaration
Public Shared Function IsEntered ( _
	obj As Object _
) As Boolean

Parameters

obj
Type: System.Object
The object to test.

Return Value

Type: System.Boolean
true if the current thread holds a lock on obj; otherwise, false.

The IsEntered method applies to locks that are taken by using the methods of the Monitor class (that is, the Enter, TryEnter, and Wait methods), and to locks that are taken by using the C# lock statement and the Visual Basic SyncLock statement, because the implementations of those statements use the Monitor class.

Use the IsEntered method with asserts and code contracts to diagnose problems with locks. For example, the following code shows a method that begins by asserting that the current thread has taken a lock on a global object.

Shared Sub ExampleMethod()
    Debug.Assert(Monitor.IsEntered(globalLockObject));
    ' Other code.
End Sub

Windows Phone OS

Supported in: 8.1, 8.0

Show:
© 2017 Microsoft