Lock.EnterScope Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Enters the lock, waiting if necessary until the lock can be entered.
public:
System::Threading::Lock::Scope EnterScope();
public System.Threading.Lock.Scope EnterScope ();
member this.EnterScope : unit -> System.Threading.Lock.Scope
Public Function EnterScope () As Lock.Scope
Returns
A Lock.Scope that can be disposed to exit the lock.
Exceptions
The lock has reached the limit of repeated entries by the current thread. The limit is implementation-defined and is intended to be high enough that it would not be reached in normal situations.
Remarks
If the lock can't be entered immediately, the method waits until the lock can be entered. If the lock is already held by the current thread, the lock is entered again. To fully exit the lock and allow other threads to enter the lock, the current thread should dispose the returned Lock.Scope to exit the lock as many times as it has entered the lock.
This method is intended to be used with a language construct that automatically disposes the Lock.Scope, such as the C# using
keyword.
For more information, see the Remarks for Lock.
Applies to
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for