I want to control the amount of tasks that are running at a time. I have a number of tasks stored in an array. This is how I am controlling their start
for (var j = 0; j < tasks.Count; j++)
{
tasks[j].Start();
if (j % 10 == 0 || j > 10)
{
Task.WaitAny(tasks.ToArray());
Console.Write(".");
}
}
However, it looks like this isn't starting 10, then waiting for one to finish before completing the iteration and moving on to the next one. Instead, it appears to be waiting for 1 to complete then I'm seeing a stream of ".". Why? Is there a better approach?