Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uses of a concurrent dictionary [closed]

Tags:

c#

.net

c#-4.0

Where do you think one could find usages for the Concurrent Dictionary thats part of the .Net framework 4?

Has anybody used the Concurrent Dictionary, if so why? Examples if any would be great.

I can think of its uses in the factory pattern wherein you want to store different instances of a class if it has been initialized already. Eg. Hibernates SessionFactory. What do you think?

like image 304
Baz1nga Avatar asked Dec 28 '22 15:12

Baz1nga


2 Answers

I've used it heavily for caching scenarios. ConcurrentDictionary, especially when combined with Lazy<T>, is great for caching results when construction of a type is expensive, and works properly in multithreaded scenarios.

like image 83
Reed Copsey Avatar answered Dec 30 '22 09:12

Reed Copsey


Whenever I don't want to worry about concurrent access to the dictionary really - i.e. I have some tiny HTTP web server app which logs/caches some request data in a dictionary structure - there can be any number of concurrent requests and I don't want to deal with having to manually lock the dictionary.

It's just one more thing that you don't have to do yourself and potentially get wrong, instead the framework takes care of that aspect for you.

like image 30
BrokenGlass Avatar answered Dec 30 '22 10:12

BrokenGlass