This is more of an academic question... but can ConcurrentDictionary.TryAdd fail? And if so in what cases and why?
To retrieve single item, ConcurrentDictionary provides TryGetValue method. We have to provide Key in the TryGetValue method. It takes the out parameter to return the value of key. TryGetValue returns true if key exists, or returns false if key does not exists in dictionary.
It is thread-safe and internally uses locking. It is useful in the case of a multi-threaded application. However, ConcurrentDictionary is slower than Dictionary.
adjective. occurring or existing simultaneously or side by side: concurrent attacks by land, sea, and air. acting in conjunction; cooperating: the concurrent efforts of several legislators to pass the new law. having equal authority or jurisdiction: two concurrent courts of law.
Yes it can, here are the conditions (from msdn):
Just to reiterate, this is nothing to do with concurrency. If you worry about two threads inserting an item at the same time then the following can happen:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With