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
c#
So the question is when should I use EnterReadLock() and EnterWriteLock() when accessing the Dictionary?
- TryGetValue. I think a ReadLock should be ok here.
- Updating the Dictionary using the Indexer e.g. _dic[existingKey] = NewValue. I think a ReadLock should be OK here.
- 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