Mono Class Library: System.Threading.Monitor Overview | Members

System.Threading.Monitor.TryEnter Method

Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object. [Edit]

public static bool TryEnter (object obj, TimeSpan timeout)

Parameters

obj
The object on which to acquire the lock. [Edit]
timeout
A TimeSpan set to the maximum amount of time to wait for the lock. [Edit]
timeout
Documentation for this section has not yet been entered. [Edit]

Returns

true if the current thread acquires the lock; otherwise, false. [Edit]

Exceptions

TypeReason
ArgumentNullExceptionobj is null. [Edit]
ArgumentOutOfRangeExceptionThe value of timeout in milliseconds is negative and is not equal to Timeout.Infinite , or is greater than int.MaxValue . [Edit]

Remarks

If successful, this method acquires an exclusive lock on obj.

If the value of timeout converted to milliseconds equals Timeout.Infinite, this method is equivalent to Monitor.Enter(object) (obj). If the value of timeout equals zero, this method is equivalent to Monitor.TryEnter(object) (obj).

[Edit]

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0