1

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?

user3791372
  • 4,445
  • 6
  • 44
  • 78
  • 1
    If you are not removing tasks from array, WaitAny sees that there are already completed tasks there and returns immediatly (there is nothing to wait). – Evk Dec 31 '16 at 23:05
  • 1
    what do you want to do? I did not get it? do you want to start task number 10? – Green Falcon Dec 31 '16 at 23:05

0 Answers0