ReaderWriterLockSlim and async\await

ReaderWriterLockSlim is a thread-affine lock type, so it usually cannot be used with async and await.

You should either use SemaphoreSlim with WaitAsync, or (if you really need a reader/writer lock), use my AsyncReaderWriterLock from AsyncEx or Stephen Toub’s AsyncReaderWriterLock.

Leave a Comment