Export (0) Print
Expand All

ReaderWriterLock.UpgradeToWriterLock Method (TimeSpan)

Upgrades a reader lock to the writer lock, using a TimeSpan value for the time-out.

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public LockCookie UpgradeToWriterLock(
	TimeSpan timeout
)

Parameters

timeout
Type: System.TimeSpan

The TimeSpan specifying the time-out period.

Return Value

Type: System.Threading.LockCookie
A LockCookie value.

ExceptionCondition
ApplicationException

timeout expires before the lock request is granted.

ArgumentOutOfRangeException

timeout specifies a negative value other than -1 milliseconds.

When a thread calls UpgradeToWriterLock the reader lock is released, regardless of the lock count, and the thread goes to the end of the queue for the writer lock. Thus, other threads might write to the resource before the thread that requested the upgrade is granted the writer lock.

Important noteImportant

The time-out exception is not thrown until the thread that called the UpgradeToWriterLock method can reacquire the reader lock. If there are no other threads waiting for the writer lock, this happens immediately. However, if another thread is queued for the writer lock, the thread that called the UpgradeToWriterLock method cannot reacquire the reader lock until all current readers have released their locks, and one thread has acquired and released the writer lock. This is true even if the other thread that requested the writer lock requested it after the current thread called the UpgradeToWriterLock method.

To restore the lock state, call DowngradeFromWriterLock using the LockCookie returned by UpgradeToWriterLock. Do not use this LockCookie with RestoreLock.

When a thread has no reader lock, do not use UpgradeToWriterLock. Use AcquireWriterLock instead.

For valid time-out values, see ReaderWriterLock.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft