title: ThreadPool.QueueUserWorkItem with a lambda expression and anonymous method
body: <p>Passing two parameters to a new thread on the threadpool can sometimes be complicated, but it appears that with lambda expressions and anonymous methods, I can do this:</p>
  
  <pre><code>public class TestClass
  {
      public void DoWork(string s1, string s2)
      {
          Console.WriteLine(s1);
          Console.WriteLine(s2);
      }
  }
  
  try
  {
      TestClass test = new TestClass();
      string s1 = "Hello";
      string s2 = "World";
      ThreadPool.QueueUserWorkItem(
          o =&gt; test.DoWork(s1, s2)
          );
  }
  catch (Exception ex)
  {
      //exception logic
  }
  </code></pre>
  
  <p>Now, I've certainly simplified this example, but these points are key:</p>
  
  <ul>
  <li>The string objects being passed are immutable and therefore threadsafe</li>
  <li>The s1 and s2 variables are declared within the scope of the try block, which I exit immediately after queuing the work to the thread pool, so the s1 and s2 variables are never modified after that.</li>
  </ul>
  
  <p>Is there something wrong with this?</p>
  
  <p>The alternative is to create a new class that implements an immutable type with 3 members: test, s1, and s2.  That just seems like extra work with no benefit at this point.</p>