Version of TryEnter that will block, but only up to a timeout period.
[Visual Basic] Overloads Public Shared Function TryEnter( _ ByVal obj As Object, _ ByVal timeout As TimeSpan _ ) As Boolean [C#] public static bool TryEnter( object obj, TimeSpan timeout ); [C++] public: static bool TryEnter( Object* obj, TimeSpan timeout ); [JScript] public static function TryEnter( obj : Object, timeout : TimeSpan ) : Boolean;
True if the current thread can acquire the monitor lock without blocking; otherwise, False.
Exception Type | Condition |
---|---|
ArgumentNullException | If obj is a null reference (in Visual Basic Nothing). |
ArgumentException | If obj is a value type. |
ArgumentException | If timeout is negative or greater than MaxValue. |
If timeout equals Infinite, this method becomes equivalent to Enter.
Monitor Class | Monitor Members | System.Threading Namespace | Monitor.TryEnter Overload List | Thread