title: Adding to a list in a Parallel.ForEach loop in a threadsafe manner
body: <p>I have a bit of code that works like this on a list of obj objects called ListofObjects:</p>
  
  <pre><code>List&lt;SomeObject&gt; NewListofObjects&lt;SomeObject&gt;();
  
  Parallel.ForEach(ListofObjects, obj =&gt;
  
  //Do some operations here on obj to get a newobj
  
  NewListofObjects.Add(newobj);
  
  );
  </code></pre>
  
  <p>Now I am out of the Parallel.ForEach loop, and I want to do an operation on NewListofObjects. However, I get this error when I try to: <strong>"Attempted to read or write protected memory. This is often an indication that other memory is corrupt".</strong></p>
  
  <p>Is this because my NewListofObjects.Add(newobj) method is not threadsafe? If so, how can I make it threadsafe?</p>