Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SpinLock::TryEnter Method (Boolean%)

.NET Framework (current version)
 

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:  mscorlib (in mscorlib.dll)

public:
void TryEnter(
	bool% lockTaken
)

Parameters

lockTaken
Type: System::Boolean%

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

Exception Condition
ArgumentException

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

LockRecursionException

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

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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft