title: Correct use of Parallel for loop in C#?
body: <p>In this example, is this the correct use of the <code>Parallel.For</code> loop if I want to limit the number of threads that can perform the function <code>DoWork</code> to ten at a time? Will other threads be blocked until one of the ten threads becomes available? If not, what is a better multi-threaded solution that would still let me execute that function 6000+ times? </p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          ThreadExample ex = new ThreadExample(); 
      }
  }
  
  public class ThreadExample
  {
      int limit = 6411; 
  
      public ThreadExample()
      {
          Console.WriteLine("Starting threads...");
          int temp = 0; 
          Parallel.For(temp, limit, new ParallelOptions { MaxDegreeOfParallelism = 10 }, i =&gt;
          {
              DoWork(temp);
              temp++; 
          }); 
      }
  
      public void DoWork(int info)
      {
          //Thread.Sleep(50); //doing some work here. 
  
          int num = info * 5; 
  
          Console.WriteLine("Thread: {0}      Result: {1}", info.ToString(), num.ToString());
      }
  }
  </code></pre>