ReaderWriterLock allows many readers and an exclusive writer. I have to share it because it really nice functionality.
Creating a reader writer lock
private static ReaderWriterLockSlim _rw = new ReaderWriterLockSlim();
Locking and unlocking as reader
_rw.EnterReadLock();
try
{
//Do synchronized stuff
}
finally
{
_rw.ExitReadLock();
}
Locking and unlocking as writer
_rw.EnterWriteLock();
try
{
//Do synchronized stuff
}
finally
{
_rw.ExitWriteLock();
}