Search code examples
c#-4.0concurrencydictionarytrygetvalue

Is bool ConcurrentDictionary<TKey, TValue>.TryGetValue(TKey, out TValue) method thread-safe?


It's not quite clear from this post: https://devblogs.microsoft.com/pfxteam/concurrentdictionarys-support-for-adding-and-updating/


Solution

  • Sure. Otherwise it would be useless, as this is a thread safe alternative to Dictionary<TKey, TValue>. See the documentation: http://msdn.microsoft.com/en-us/library/dd287191.aspx:

    Thread Safety

    All public and protected members of ConcurrentDictionary<TKey, TValue> are thread-safe and may be used concurrently from multiple threads.