title: Modifying list from another thread while iterating (C#)
body: <p>I'm looping through a List of elements with foreach, like this:</p>
  
  <pre><code>foreach (Type name in aList) {
     name.doSomething();
  }
  </code></pre>
  
  <p>However, in an another thread I am calling something like</p>
  
  <pre><code>aList.Remove(Element);
  </code></pre>
  
  <p>During runtime, this causes an InvalidOperationException: Collection was modified; enumeration operation may not execute. What is the best way to handle this (I would perfer it to be rather simple even at the cost of performance)?</p>
  
  <p>Thanks!</p>