c# - How to manage adding and removing specific items from collection with multiple threads? -


i have many threads can add items collection , remove specific items collection on condition. in first project, readers more writers. in second project, readers may more writers or equal or less.

  1. how should manage add/remove collection?
  2. what collection use? simple list blocking on add/remove?
  3. which blocking mechanism use(lock, readerwriterlockslim,...)?

you can use data structures namespace system.collections.concurrent. encapsulate 3 aspects mentioned , can used concurrent threads without explicit locking.

see: system.collections.concurrent namespace @ msdn

for example concurrentbag<t> has icollection interface , thread-safe implementation, optimized scenarios same thread both producing , consuming data stored in bag.

if need quick object lookup might use concurrentdictionary<tkey, tvalue>.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -