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

System.Threading.Monitor.TryEnter Method

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

public static bool TryEnter (object obj, int millisecondsTimeout)

Parameters

obj
The object on which to acquire the lock. [Edit]
millisecondsTimeout
A int containing the maximum number of milliseconds to wait for the lock. [Edit]
millisecondsTimeout
Documentation for this section has not yet been entered. [Edit]

Returns

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

Exceptions

TypeReason
ArgumentNullExceptionobj is null. [Edit]
ArgumentOutOfRangeExceptionmillisecondsTimeout is negative, and not equal to Timeout.Infinite . [Edit]

Remarks

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

If millisecondsTimeout equals Timeout.Infinite, this method is equivalent to Monitor.Enter(object) (obj). If millisecondsTimeout 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