Waits for notification passed by the execution engine from the object (via the Pulse or PulseAll method). The Wait method must be invoked from within a synchronized block of code.
This method acquires the monitor waithandle for the object. If this thread holds the monitor lock for the object, it releases it. On exit from the method, it obtains the monitor lock back.
Waits for notification from an object which called the Pulse or PulseAll method or for a specified timer to elapse. If exitContext is true then the synchronization domain for the context (if in a synchronized context) is exited before the wait and reacquired.
[Visual Basic] Overloads Public Shared Function Wait(Object, TimeSpan, Boolean) As Boolean
[C#] public static bool Wait(Object, TimeSpan, bool);
[C++] public: static bool Wait(Object*, TimeSpan, bool);
[JScript] public static function Wait(Object, TimeSpan, Boolean) : Boolean;
Waits for notification from an object which called the Pulse or PulseAll method or for a specified timer to elapse. If exitContext is true then the synchronization domain for the context (if in a synchronized context) is exited before the wait and reacquired.
[Visual Basic] Overloads Public Shared Function Wait(Object, Integer, Boolean) As Boolean
[C#] public static bool Wait(Object, int, bool);
[C++] public: static bool Wait(Object*, int, bool);
[JScript] public static function Wait(Object, int, Boolean) : Boolean;
Waits for notification from an object which called the Pulse or PulseAll method or for a specified timer to elapse.
[Visual Basic] Overloads Public Shared Function Wait(Object, Integer) As Boolean
[C#] public static bool Wait(Object, int);
[C++] public: static bool Wait(Object*, int);
[JScript] public static function Wait(Object, int) : Boolean;
Waits for notification passed by the execution engine from an object, which called the Pulse or PulseAll method.
[Visual Basic] Overloads Public Shared Function Wait(Object) As Boolean
[C#] public static bool Wait(Object);
[C++] public: static bool Wait(Object*);
[JScript] public static function Wait(Object) : Boolean;
Waits for notification from an object which called the Pulse or PulseAll method or for a specified timer to elapse.
[Visual Basic] Overloads Public Shared Function Wait(Object, TimeSpan) As Boolean
[C#] public static bool Wait(Object, TimeSpan);
[C++] public: static bool Wait(Object*, TimeSpan);
[JScript] public static function Wait(Object, TimeSpan) : Boolean;
These examples resolve an issue that arises when the Pulse method is invoked before the Wait method. Note: this code is provided for illustrative purposes only; it will not work with current builds.
Example 1 (This code may hang if Pulse is invoked before Wait.)
Monitor Class | Monitor Members | System.Threading Namespace