Last post Nov 06, 2013 07:49 AM by Illeris
Nov 06, 2013 07:39 AM|Ringoo|LINK
I was taking a look at the classes in the System.Collections.Concurrent namespace. I was wondering if thread - safety is the only default feature provided with the classes in this namespace. Or is there anything in them that makes
it possible for a developer to pick up different parts of them and process them in parallel. For instance, is there anything inherent about the ConcurrentDictionary<TKey, TValue> class that would make it easier for me to split a 1000 element instance of it
into 10 parts and process each concurrently, in order to make processing faster?
Please let me know.
Nov 06, 2013 07:49 AM|Illeris|LINK
Feature is perhaps not the best description for this. If it would not be thread-safe, it would simply not work in concurrent mode. Meaning that multiple operations in parallel in the same appdomain would cause issues, unless you write something around the
collection classes in order to assure thread safety.
For concurrent programming, you have the choice between multi-threading and the .NET parallel programming extensions (http://msdn.microsoft.com/en-us/library/dd460693(v=vs.110).aspx).
Both have their advantages and disadvantages.
For the example you give on splitting 1000 in parts of 10: do not assume it will go faster by default. Parallel execution on the same processor implies context switching. This also consumes resources. Apply this wisely !