<p>I'm looking for a way of getting a <strong>concurrent collection</strong> in <strong>C#</strong> or at least a collection which supports a <strong>concurrent enumerator</strong>.  Right now I'm getting an <code>InvalidOperationException</code> when the collection over which I'm iterating changes.  </p>

<p>I could just deep copy the collection and work with a private copy but I'm wondering  if there is perhaps a better way</p>

<p>Code snippet:</p>

<pre class="lang-cs prettyprint-override"><code>foreach (String s in (List&lt;String&gt;) callingForm.Invoke(callingForm.delegateGetKillStrings))
{
    //do some jazz
}
</code></pre>

<p>--edit--</p>

<p>I took the answer but also found that I needed to ensure that the code which was writing to the collection needed to attempt to get a lock as well.</p>

<pre class="lang-cs prettyprint-override"><code>private void addKillString(String s)
{
    lock (killStrings)
    {
        killStrings.Add(s);
    }
}
</code></pre>

Other than doing a deep-copy your best bet might be to lock the collection:
```
```
List<string> theList = (List<String> )callingForm.Invoke(callingForm.delegateGetKillStrings);
    lock(theList.SyncRoot) {
        foreach(string s in theList) {
               // Do some Jazz
        }
    }
```
```