How should I ReaderWriterLockSlim and Dictionary<MyKeyClass,MyValueClass>?

Posted by DayOne on Stack Overflow See other posts from Stack Overflow or by DayOne
Published on 2010-05-25T16:15:08Z Indexed on 2010/05/25 16:21 UTC
Read the original article Hit count: 159

Filed under:

So the question is when should I use EnterReadLock() and EnterWriteLock() when accessing the Dictionary?

  1. TryGetValue. I think a ReadLock should be ok here.
  2. Updating the Dictionary using the Indexer e.g. _dic[existingKey] = NewValue. I think a ReadLock should be OK here.
  3. Add a new item using the Indexer e.g. _dic[newKey] = NewValue. I think I need a WriteLock here.

Thanks in advance!

© Stack Overflow or respective owner

Related posts about c#