In general, the Contains operation is not very useful in a parallel collection. The problem is that as soon as you define the collection βcontainsβ or does not contain any object, the logic that you perform as a result of this check is no longer valid, since another thread can add or remove an element immediately after.
The ConcurrentDictionary class contains this method for implementing IDictionary, but the intended use should actually use AddOrUpdate , GetOrAdd and similar atomic methods.
source share