When working with a concurrent collection (for example ConcurrentDictionary) should I use TryAdd method, or just a plain old index assignment? I mean, do TryAdd method blocks when adding, so if another thread would try to remove the value it would have to wait until add is complete?
When working with a concurrent collection (for example ConcurrentDictionary) should I use TryAdd method,
Share
The prefix
tryhas nothing to do with thread safety. It is just exception-free version ofAdd.