Muokkaa

Jaa


SpinLock.TryEnter Method

Definition

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.

Overloads

TryEnter(Boolean)

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.

TryEnter(Int32, Boolean)

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.

TryEnter(TimeSpan, Boolean)

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.

TryEnter(Boolean)

Source:
SpinLock.cs
Source:
SpinLock.cs
Source:
SpinLock.cs

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.

public:
 void TryEnter(bool % lockTaken);
public void TryEnter (ref bool lockTaken);
member this.TryEnter : bool -> unit
Public Sub TryEnter (ByRef lockTaken As Boolean)

Parameters

lockTaken
Boolean

True if the lock is acquired; otherwise, false. lockTaken must be initialized to false prior to calling this method.

Exceptions

The lockTaken argument must be initialized to false prior to calling TryEnter.

Thread ownership tracking is enabled, and the current thread has already acquired this lock.

Remarks

Unlike Enter, TryEnter will not block waiting for the lock to be available. If the lock is not available when TryEnter is called, it will return immediately without any further spinning.

See also

Applies to

TryEnter(Int32, Boolean)

Source:
SpinLock.cs
Source:
SpinLock.cs
Source:
SpinLock.cs

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.

public:
 void TryEnter(int millisecondsTimeout, bool % lockTaken);
public void TryEnter (int millisecondsTimeout, ref bool lockTaken);
member this.TryEnter : int * bool -> unit
Public Sub TryEnter (millisecondsTimeout As Integer, ByRef lockTaken As Boolean)

Parameters

millisecondsTimeout
Int32

The number of milliseconds to wait, or Infinite (-1) to wait indefinitely.

lockTaken
Boolean

True if the lock is acquired; otherwise, false. lockTaken must be initialized to false prior to calling this method.

Exceptions

millisecondsTimeout is a negative number other than -1, which represents an infinite time-out.

The lockTaken argument must be initialized to false prior to calling TryEnter.

Thread ownership tracking is enabled, and the current thread has already acquired this lock.

Remarks

Unlike Enter, TryEnter will not block indefinitely waiting for the lock to be available. It will block until either the lock is available or until the millisecondsTimeout has expired.

See also

Applies to

TryEnter(TimeSpan, Boolean)

Source:
SpinLock.cs
Source:
SpinLock.cs
Source:
SpinLock.cs

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.

public:
 void TryEnter(TimeSpan timeout, bool % lockTaken);
public void TryEnter (TimeSpan timeout, ref bool lockTaken);
member this.TryEnter : TimeSpan * bool -> unit
Public Sub TryEnter (timeout As TimeSpan, ByRef lockTaken As Boolean)

Parameters

timeout
TimeSpan

A TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely.

lockTaken
Boolean

True if the lock is acquired; otherwise, false. lockTaken must be initialized to false prior to calling this method.

Exceptions

timeout is a negative number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater than Int32.MaxValue milliseconds.

The lockTaken argument must be initialized to false prior to calling TryEnter.

Thread ownership tracking is enabled, and the current thread has already acquired this lock.

Remarks

Unlike Enter, TryEnter will not block indefinitely waiting for the lock to be available. It will block until either the lock is available or until the timeout has expired.

See also

Applies to