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.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- obj
- Type: System.Object
The object to test.
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.