Export (0) Print
Expand All

ReaderWriterLockSlim.ExitReadLock Method

Reduces the recursion count for read mode, and exits read mode if the resulting count is 0 (zero).

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

'Declaration
Public Sub ExitReadLock

ExceptionCondition
SynchronizationLockException

The current thread has not entered the lock in read mode.

This method is not sensitive to recursion order. For example, if a thread enters a lock in upgradeable mode and then enters the lock in read mode, the order in which the thread exits the two modes does not matter. If a lock allows recursion, a thread can enter the lock in write mode and then enter it recursively in read mode; the order in which the thread exits read mode and write mode does not matter.

Exiting the lock might signal other waiting threads.

The following example shows how to use a finally block to execute the ExitReadLock method, ensuring that the caller exits read mode. The method shown in the example retrieves the value associated with a key. If the key is not found, the exception thrown by the inner Dictionary(Of TKey, TValue) is allowed to terminate the method. The EnterReadLock method is used to enter read mode.

This code is part of a larger example provided for the ReaderWriterLockSlim class.

Private cacheLock As New ReaderWriterLockSlim()
Private innerCache As New Dictionary(Of Integer, String)


...


Public Function Read(ByVal key As Integer) As String
    cacheLock.EnterReadLock()
    Try 
        Return innerCache(key)
    Finally
        cacheLock.ExitReadLock()
    End Try 
End Function

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, 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