Teet Kalm
Teet Kalm

Reputation: 49

c#, "collection modified" inside locked block

I'm having problem with following code: error

 protected Dictionary<string, object> values;
 
 lock (values)
   foreach (KeyValuePair<string, object> k in values) // error here
     {} //do something here

In some reason, I'm getting collection was modified error near k, although I have locked values. Why's that? As I understand, other modifying processes should wait behind locked code block, until it's finished.

Upvotes: -2

Views: 39

Answers (0)

Related Questions