title: Starting a thread with / without delegate()
body: <p>What is the difference between:</p>
  
  <pre><code>new Thread(new ThreadStart(SomeFunc))
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>new Thread( delegate() { SomeFunc();} )
  </code></pre>
  
  <p>This code gives strange outputs on my computer:</p>
  
  <pre><code>public class A
  {
      int Num;
  
      public A(int num)
      {
          Num = num;
      }
  
      public void DoObj(object obj)
      {
          Console.Write(Num);
      }
  
      public void Do()
      {
          Console.Write(Num);
      }
  }
  
  /////// in void main()
  
  for (int i = 0; i &lt; 10; i++)
  {
      (new Thread(new ThreadStart((new A(i)).Do))).Start(); // Line 1
      (new Thread(new ThreadStart(delegate() { (new A(i)).Do(); }))).Start(); // Line 2
      (new Thread(delegate() { (new A(i)).Do(); })).Start(); // Line 3
  }
  </code></pre>
  
  <p>If only Line 1 is executed the output is something like:</p>
  
  <blockquote>
    <p>0 2 3 1 5 6 4 7 8 9 </p>
  </blockquote>
  
  <p>which is ok but if Line 2 or 3 is executed, output is:</p>
  
  <blockquote>
    <p>3 3 3 5 5 7 7 9 9 10</p>
  </blockquote>
  
  <p>There are some multiple numbers and a 10 which is quite strange that the loop is never run with the number 10. What is the trick behind these?</p>
  
  <p>Thanks.</p>