Monitor.TryEnter Method (Object)
Attempts to acquire an exclusive lock on the specified object.
Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Parameters
- obj
- Type: System.Object
The object on which to acquire the lock.
| Exception | Condition |
|---|---|
| ArgumentNullException | The obj parameter is a null reference (Nothing in Visual Basic). |
If successful, this method acquires an exclusive lock on the obj parameter. This method returns immediately, whether or not the lock is available.
This method is similar to Enter, but it will never block. If the thread cannot enter without blocking, the method returns false, and the thread does not enter the critical section.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note