Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within
the method call, lockTaken can be examined reliably to determine whether the
lock was acquired.
Namespace:
System.Threading
Assembly:
System.Threading (in System.Threading.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Sub TryEnter ( _
millisecondsTimeout As Integer, _
ByRef lockTaken As Boolean _
) |
C# |
---|
public void TryEnter(
int millisecondsTimeout,
ref bool lockTaken
) |
Parameters
- millisecondsTimeout
- Type: System..::.Int32
The number of milliseconds to wait, or Infinite (-1) to wait indefinitely.
- lockTaken
- Type:
System..::.Boolean
%
True if the lock is acquired; otherwise, false. lockTaken must be initialized to false prior to calling this method.
Remarks
Exceptions
Exception | Condition |
---|
System.Threading..::.LockRecursionException |
Thread ownership tracking is enabled, and the current thread has already acquired this lock.
|
System..::.ArgumentException |
The lockTaken argument must be initialized to false prior to calling TryEnter.
|
System..::.ArgumentOutOfRangeException | millisecondsTimeout is
a negative number other than -1, which represents an infinite time-out. |
See Also