I have a class that maintains a private Dictionary
instance that caches some data.
The class writes to the dictionary from multiple threads using a
If you want a snapshot of the current state of the dictionary, there's really nothing else you can do with this collection type. This is the same technique used by the ConcurrentDictionary
If you don't mind throwing an InvalidOperationException
if the collection is modified while you are enumerating it, you could just return cache.Values
since it's readonly (and thus can't corrupt the dictionary data).