Static Dictionary needs to be threadsafe - Suggestions?
<p>I currently have a static dictionary in my class. Although I have implemented locks on this dictionary yet I get the following error.</p>

<pre><code>An InvalidOperationException has occurred. It reports a "collection was modified" error 
</code></pre>

<p>The reason for this is that at times one method is reading the dictionary using foreach while another thread is removing or adding items to it. I read that adding </p>

<pre><code>lock ( (  (IDictionary&lt;string,string&gt;)dict_object).SyncRoot )
</code></pre>

<p>on all the operations where reading/writing/removing is taking place will resolve the issue however I keep on getting the message</p>

<pre><code>does not contain a definition of SyncRoot are you missing a using directive
</code></pre>

<p>any suggestions on how I could resolve this issue ? Any other way on how I could make my static dictionary threadsafe ? I am using .Net 4.0</p>
