title: Thread Safety and Task.Factory
body: <p>I'm quite new in parallel programing<br>
  i'd like to do some work with tasks<br>
  every task is initiated with param to do some simple work with id<br>
  but it seems the params all mixed up..     </p>
  
  <p>i'm sure i'm missing some key element in thread safety<br>
  can you help me understand what i'm doing wrong ? </p>
  
  <p>i don't need any return value from the tasks, i just need them to finish their work.   </p>
  
  <pre><code>static void Main(string[] args)
  {
      int NumberOfTasks = 10;
  
      Task[] tasks = new Task[NumberOfTasks];
      for (int i = 0; i &lt; NumberOfTasks; i++)
      {
         tasks[i] = Task.Factory.StartNew(() =&gt; DoSafeWork(i));
      }
      Task.WaitAll(tasks);
  
      Console.WriteLine("Done !");
      Console.ReadKey();
  }
  
  private static void DoSafeWork(int i)
  {
      Console.WriteLine("working on Task {0} ", i.ToString());
  }
  </code></pre>
  
  <p>Current output (possible):</p>
  
  <pre><code>working on Task 3    
  working on Task 6    
  working on Task 10    
  working on Task 10    
  working on Task 10    
  working on Task 10    
  working on Task 10    
  working on Task 10    
  working on Task 10    
  working on Task 10    
  Done !
  </code></pre>