title: Starting a new thread in a foreach loop
body: <p>I have a List of objects and I'd like to loop over that list and start a new thread, passing in the current object.</p>
  
  <p>I've written an example of what I thought should do this, but it's not working. Specifically, it seems like the threads are getting overwritten on each iteration. This doesn't really make sense to me though because I'm making a new Thread object each time.</p>
  
  <p>This is the test code I wrote</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          TestClass t = new TestClass();
          t.ThreadingMethod();
      }
  }
  
  class TestClass
  {
      public void ThreadingMethod()
      {
          var myList = new List&lt;MyClass&gt; { new MyClass("test1"), new MyClass("test2") };
  
          foreach(MyClass myObj in myList)
          {
              Thread myThread = new Thread(() =&gt; this.MyMethod(myObj));
              myThread.Start();
          }
      }
  
      public void MyMethod(MyClass myObj) { Console.WriteLine(myObj.prop1); }
  }
  
  class MyClass
  {
      public string prop1 { get; set; }
  
      public MyClass(string input) { this.prop1 = input; }
  }
  </code></pre>
  
  <p>The output on my machine is</p>
  
  <pre><code>test2
  test2
  </code></pre>
  
  <p>but I expected it to be</p>
  
  <pre><code>test1
  test2
  </code></pre>
  
  <p>I tried changing the thread lines to</p>
  
  <pre><code>ThreadPool.QueueUserWorkItem(x =&gt; this.MyMethod(myObj));
  </code></pre>
  
  <p>but none of the threads started.</p>
  
  <p>I think I just have a misunderstanding about how threads are supposed to work. Can someone point me in the right direction and tell me what I'm doing wrong?</p>