Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
Tries to enter the lock in read mode, with an optional time-out.
TryEnterReadLock(Int32) |
Tries to enter the lock in read mode, with an optional integer time-out. |
TryEnterReadLock(TimeSpan) |
Tries to enter the lock in read mode, with an optional time-out. |
Tries to enter the lock in read mode, with an optional integer time-out.
public:
bool TryEnterReadLock(int millisecondsTimeout);
public bool TryEnterReadLock(int millisecondsTimeout);
member this.TryEnterReadLock : int -> bool
Public Function TryEnterReadLock (millisecondsTimeout As Integer) As Boolean
The number of milliseconds to wait, or -1 (Infinite) to wait indefinitely.
true
if the calling thread entered read mode, otherwise, false
.
The RecursionPolicy property is NoRecursion and the current thread has already entered the lock.
-or-
The recursion number would exceed the capacity of the counter. The limit is so large that applications should never encounter it.
The value of millisecondsTimeout
is negative, but it is not equal to Infinite (-1), which is the only negative value allowed.
The ReaderWriterLockSlim object has been disposed.
If millisecondsTimeout
is 0 (zero), this method checks the lock state and returns false
immediately if the desired state is unavailable.
Multiple threads can enter read mode at the same time.
If one or more threads are waiting to enter write mode, a thread that calls the TryEnterReadLock method blocks until those threads have either timed out or entered write mode and then exited from it, or until the calling thread's own time-out interval expires.
Note
If a lock allows recursion, a thread that has entered the lock in read mode can enter read mode recursively, even if other threads are waiting to enter write mode.
One thread can be in upgradeable mode while other threads are in read mode. If additional threads are waiting to enter upgradeable mode, and there are no threads waiting to enter write mode, threads that call the TryEnterReadLock method enter read mode immediately and do not block.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Tries to enter the lock in read mode, with an optional time-out.
public:
bool TryEnterReadLock(TimeSpan timeout);
public bool TryEnterReadLock(TimeSpan timeout);
member this.TryEnterReadLock : TimeSpan -> bool
Public Function TryEnterReadLock (timeout As TimeSpan) As Boolean
The interval to wait, or -1 milliseconds to wait indefinitely.
true
if the calling thread entered read mode, otherwise, false
.
The RecursionPolicy property is NoRecursion and the current thread has already entered the lock.
-or-
The recursion number would exceed the capacity of the counter. The limit is so large that applications should never encounter it.
The value of timeout
is negative, but it is not equal to -1 milliseconds, which is the only negative value allowed.
-or-
The value of timeout
is greater than Int32.MaxValue milliseconds.
The ReaderWriterLockSlim object has been disposed.
If timeout
is 0 (zero), this method checks the lock state and returns false
immediately if the desired state is unavailable.
Multiple threads can enter the lock in read mode at the same time.
If one or more threads are queued to enter write mode, a thread that calls the TryEnterReadLock method blocks until those threads have either timed out or entered write mode and then exited from it, or until the calling thread's own time-out interval expires.
Note
If a lock allows recursion, a thread that has entered the lock in read mode can enter read mode recursively, even if other threads are waiting to enter write mode.
One thread can be in upgradeable mode while other threads are in read mode. If additional threads are waiting to enter upgradeable mode, and there are no threads waiting to enter write mode, threads that call the TryEnterReadLock method enter read mode immediately and do not block.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in