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.
currently I have this;
foreach (DataRow dtRow in urlTable.Rows)
{
for (int i = 0; i < 4; i++)
{
Thread thread = new Thread(() => MasterCrawlerClass.MasterCrawlBegin(dtRow));
thread.Start();
}
}
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.