title: Not thread safe - public static List<T>
body: <p>I was reading in MSDN that a List is thread safe when used as a public static type . However the following code snippet proves otherwise. I am trying to add and remove elements from the list but the remove method throws an error midway saying index out of bounds. What is going wrong here?</p>
  
  <p>Is this a right implementation to check my theory. If not, can someone please suggest a better example.</p>
  
  <pre><code>class Program
  {
      public static List&lt;string&gt; strlist = new List&lt;string&gt;();
      public static AutoResetEvent autoEvent = new AutoResetEvent(false);
      static void Main(string[] args)
      {
  
          strlist = new List&lt;string&gt;();
          new Thread(() =&gt; 
          {
  
              for(int i=0;i&lt;10000000;i++)
              {
           strlist.Add("item1");
              }
              //Thread.Sleep(5000);
              autoEvent.Set();
          }).Start(); ;
  
          new Thread(() =&gt; {
  
           strlist.ForEach(e =&gt; strlist.Remove(e));
  
          }).Start();
  
          Console.WriteLine("Waiting");
          autoEvent.WaitOne();
          int ci = 0;
  
          strlist.ForEach(str =&gt; ci++);
          Console.WriteLine(ci.ToString() + " Done");
          Console.Read();
  
  
      }
  
  }
  </code></pre>