public int RemoveAll(Predicate <TValue> predicate)
{
IList <TKey1> list = new List <TKey1>();
rwLock.EnterUpgradeableReadLock();
try
{
foreach (KeyValuePair <TKey1, TValue> kvp in Dictionary1)
{
if (predicate(kvp.Value))
{
list.Add(kvp.Key);
}
}
IList <TKey2> list2 = new List <TKey2>(list.Count);
foreach (KeyValuePair <TKey2, TValue> kvp in Dictionary2)
{
if (predicate(kvp.Value))
{
list2.Add(kvp.Key);
}
}
rwLock.EnterWriteLock();
try
{
for (int i = 0; i < list.Count; i++)
{
Dictionary1.Remove(list[i]);
}
for (int i = 0; i < list2.Count; i++)
{
Dictionary2.Remove(list2[i]);
}
}
finally { rwLock.ExitWriteLock(); }
}
finally { rwLock.ExitUpgradeableReadLock(); }
return(list.Count);
}