Can I remove items from a ConcurrentDictionary from within an enumeration loop of that dictionary?
- by the-locster
So for example:
ConcurrentDictionary<string,Payload> itemCache = GetItems();
foreach(KeyValuePair<string,Payload> kvPair in itemCache)
{
if(TestItemExpiry(kvPair.Value))
{ // Remove expired item.
Payload removedItem;
itemCache.TryRemove(kvPair.Key, out removedItem);
}
}
Obviously with an ordinary…