What is better and why to use List as thread safe: BlockingCollection or ReaderWriterLockSlim or lock?
- by theateist
I have System.Collections.Generic.List _myList and many threads can read from it or add items to it simultaneously. From what I've read I should using 'BlockingCollection' so this will work. I also read about ReaderWriterLockSlim' and 'lock', but I don't figure out how to use them instead ofBlockingCollection`, so my question is can I do the same with:
ReaderWriterLockSlim
lock
instead of using 'BlockingCollection'. If YES, can you please provide simple example and what pros and cons of using BlockingCollection, ReaderWriterLockSlim, lock?