I'm perusing (considering writing my own thread safe dictionary) I found the following implementation.
http://devplanet.com/blogs/brianr/archive/2008/09/26/thread-safe-dictionary-in-net.aspx
It looks pretty good generally, but there's one thing that confuses me.
The following: Cannot enumerate a threadsafe dictionary. Instead, enumerate the keys or values collection
which is found in both the
public virtual IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
throw new NotSupportedException("Cannot enumerate a threadsafe dictionary. Instead, enumerate the keys or values collection");
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotSupportedException("Cannot enumerate a threadsafe dictionary. Instead, enumerate the keys or values collection");
}
What I don't get is why it's ok to enumerate the keys or values, but not the kvp's of the dictionary?
Could someone shed some light on this for me? Thanks in advance.