Vocabulary with a castle or a Slovocal dictionary?

What is preferable in a multi-threaded application:   Dictionary with blocking object or   Concurrency Dictionary

What is effective and why should I use this or that?

edit 1: Save Guid as key and bool as value.

edit 2: more than two worker threads and one user interface thread.

+5
source share
4 answers

Read the ConcurrentDictionary carefully . It has some non-obvious features.

Here are some of them:

  • AddOrUpdate, , factory , , factory - , .
  • , GetEnumerator, ( ).
  • Keys Values .
  • .

, , ConcurrentDictionary , .

, !

+4

, .

Framework 4.0:

4.0 , , levanovd. .

:

Framework v3.5, Dictionary + ReaderWriterLock ReaderWriterLockSlim.

+5

, . , . , .

+2

I think that both will ensure thread safety, but using a dictionary with a lock object will limit the number of threads that can access the Dictionary simultaneously with 1. When using a parallel dictionary, you can specify a parallel level (that is, the number of threads that can use the dictionary at the same time ) If performance matters, I believe your parallel dictionary should be your choice.

+1
source

All Articles