System.Threading.ReaderWriterLockSlim.TryEnterWriteLock Method

Tries to enter the lock in write mode, with an optional time-out.

Syntax

public bool TryEnterWriteLock (int millisecondsTimeout)

Parameters

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

Returns

true if the calling thread entered write mode, otherwise, false.

Remarks

If millisecondsTimeout is 0 (zero), this method checks the lock state and returns false immediately if the desired state is unavailable.

If other threads have entered the lock in read mode, a thread that calls the ReaderWriterLockSlim.TryEnterWriteLock(int) method blocks until those threads have exited read mode or until the time-out interval has elapsed. While threads are blocked waiting to enter write mode, additional threads that try to enter read mode or upgradeable mode block until all the threads waiting to enter write mode have either timed out or entered write mode and then exited from it.

Note:

If a lock allows recursion, a thread that has entered the lock in write mode can enter write mode recursively, even if other threads are waiting to enter write mode.

Requirements

Namespace: System.Threading
Assembly: System.Core (in System.Core.dll)
Assembly Versions: 4.0.0.0