Obtains the monitor lock for an object. Will block if another thread holds the lock. Will not block if the current thread holds the lock, however the caller must ensure that the same number of Exit calls are made as there were Enter calls.
Enter the Monitor for an object. An object is passed as a parameter. This call will block if another thread has entered the Monitor of the same object. It will not block if the current thread has previously entered the Monitor, however the caller must ensure that the same number of Exit calls are made as there were Enter calls.
Interrupt can interrupt threads waiting to enter a Monitor on an object. A ThreadInterruptedException will be thrown.
[Visual Basic] Public Shared Sub Enter( _ ByVal obj As Object _ ) [C#] public static void Enter( object obj ); [C++] public: static void Enter( Object* obj ); [JScript] public static function Enter( obj : Object );
Exception Type | Condition |
---|---|
ArgumentNullException | If obj is a null reference (in Visual Basic Nothing). |
ArgumentException | If obj is a value type. |
If another thread has executed an Enter on the object but not yet the corresponding Exit, the current thread will block until the other thread releases the object. It is legal for the same thread to invoke Enter more than once (and it will not block); however, an equal number of Exit calls must be invoked before other threads waiting on the object will unblock.
Monitor Class | Monitor Members | System.Threading Namespace | Thread