Read/Write Locks

A frequent scenario is when you have a shared resource that multiple reader threads need to access. In a scenario like this, you probably want to grant writing permissions just to a single thread to avoid concurrency problems. The .NET Framework provides the System.Threading.ReaderWriterLockSlim class, which provides a lock enabled for multiple threads reading and exclusive access for writing.

ReaderWriterLock Class

The .NET Framework still provides the ReaderWriterLock class, as in its previous versions, but it is complex and used to handle particular multithreading scenarios. Instead, as its name implies, the ReaderWriterLockSlim class is a lightweight object for reading and writing locks.

An instance of this class is declared ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.