title: How to fill a List<T> on the main-thread using Parallel.For(..)
body: <p>Imagine I have got the following Class for a student with lots of properties, lets simplify it to this:</p>
  
  <pre><code>public class Student{
      public Int64 id { get; set; }
      public String name { get; set; }
      public Int64 Age { get; set; }
  }
  </code></pre>
  
  <p>Then on the main-thread I have got the following List:</p>
  
  <pre><code>List&lt;Student&gt; allStudents = new List&lt;Student&gt;();
  </code></pre>
  
  <p>Say I have 500 students in an Excel file and I want to gather them and insert them in the list. I can do something as follows:</p>
  
  <pre><code>for(int i = startRow; i &lt; endRow; i++){
      Student s = new Student();
  
      //Perform a lot of actions to gather all the information standing on the row//
  
      allStudents.Add(s);
  }
  </code></pre>
  
  <p>Now because gathering the information in Excel is very slow, because numerous actions have to be performed. So I want to use Parallel.For, I can imagine to do the following:</p>
  
  <pre><code>Parallel.For(startRow, endRow, i =&gt; {
      Student s = new Student();
  
      //Perform a lot of actions to gather all the information standing on the row//
  
      //Here comes my problem. I want to add it to the collection on the main-thread.
      allStudents.Add(s);
  });
  </code></pre>
  
  <p>What is the correct way to implement Parallel.For in the matter described above? Should I lock the list before adding and how exactly?</p>
  
  <p>@Edit 15:52 09-07-2015</p>
  
  <p>The results of the answer below are as follows (524 records):</p>
  
  <ul>
  <li>2:09 minutes - Normal loop</li>
  <li>0:19 minutes - AsParallel loop</li>
  </ul>