title: C# MultiThreading Loop entire DataTable while limiting threads to 4
body: <p>This may be a tricky question to ask, but what I have is a DataTable that contains 1000 rows.  Foreach of these rows I want to process on a new thread.  However I want to limit the threads to 4 threads.  So basically I'm constently keeping 4 threads running until the whole datatable has been processed.</p>
  
  <p>currently I have this;</p>
  
  <pre><code>  foreach (DataRow dtRow in urlTable.Rows)
          {
              for (int i = 0; i &lt; 4; i++)
              {
                  Thread thread = new Thread(() =&gt; MasterCrawlerClass.MasterCrawlBegin(dtRow));
                  thread.Start();
              }
          }
  </code></pre>
  
  <p>I know this is backwards but i'm not sure how to achieve what I'm looking for.  I thought of a very complicated while loop but maybe that's not the best way?  Any help is always appreciated.</p>