title: multiple threads adding elements to one list. why are there always fewer items in the list than expected?
body: <p>The following code explains my question.
  I know the list is not thread safe. But what is the underlying "real" reason of this?</p>
  
  <pre><code>    class Program
  {
      static void Main(string[] args)
      {
          List&lt;string&gt; strCol = new List&lt;string&gt;();
  
          for (int i = 0; i &lt; 10; i++)
          {
              int id = i;
              Task.Factory.StartNew(() =&gt;
              {
                  AddElements(strCol);
              }).ContinueWith((t) =&gt; { WriteCount(strCol, id.ToString()); });
          }
  
          Console.ReadLine();
      }
  
      private static void WriteCount(List&lt;string&gt; strCol, string id)
      {
          Console.WriteLine(string.Format("Task {0} is done. Count: {1}. Thread ID: {2}", id, strCol.Count, Thread.CurrentThread.ManagedThreadId));
      }
  
      private static void AddElements(List&lt;string&gt; strCol)
      {
          for (int i = 0; i &lt; 20000; i++)
          {
              strCol.Add(i.ToString());
          }
      }
  }
  </code></pre>