I have a simple collection which I'm looping through like this:
foreach (MyObject mo in myObjects)
{
myObject.RunAcync();
}
RunAsync
executes code in a separate thread, using new Thread(()=>{ .. }).Start()
, it's not in my power to change the code of RunAsync
. I need to limit the number of instances of myObject
running concurrently to N (real numbers are 2..10). What is the efficient way to do that using .NET4
and c#
?