ReaderLock Class
Helper class that makes it easier to ensure proper usage of a ReaderWriterLock for readers by providing support for IDisposable and the using keyword.
Namespace: Microsoft.Practices.CompositeUI
Assembly: Microsoft.Practices.CompositeUI (in microsoft.practices.compositeui.dll)
Syntax
'Declaration
Public Class ReaderLock
Inherits LockBase
'Usage
Dim instance As ReaderLock
public class ReaderLock : LockBase
public ref class ReaderLock : public LockBase
public class ReaderLock extends LockBase
public class ReaderLock extends LockBase
Example
Common usage is as follows:
ReaderWriterLock mylock = new ReaderWriterLock();
// Inside some method
using (new ReaderLock(rwLock))
{
// Do your safe resource read accesses here.
}
If a timeout is specified, the TimedOut property should be checked inside the using statement:
ReaderWriterLock mylock = new ReaderWriterLock();
// Inside some method
using (ReaderLock l = new ReaderLock(rwLock, 100))
{
if (l.TimedOut == false)
{
// Do your safe resource read accesses here.
}
else
{
throw new InvalidOperationException("Could not lock the resource.");
}
}
Inheritance Hierarchy
System.Object
Microsoft.Practices.CompositeUI.LockBase
Microsoft.Practices.CompositeUI.ReaderLock
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
ReaderLock Members
Microsoft.Practices.CompositeUI Namespace