ReaderWriterLockSlim and async\await

前端 未结 4 1036
自闭症患者
自闭症患者 2020-12-09 14:40

I have some problems with ReaderWriterLockSlim. I cannot understand how it\'s magic working.

My code:

 private async Task LoadIndex()
           


        
4条回答
  •  清歌不尽
    2020-12-09 15:33

    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.

提交回复
热议问题