Sorry, I don't understand the difference between using the library and just creating the tasks on their own. The following also resolves in 22 seconds total.
public async Task TestTypical()
{
var sw = new Stopwatch();
sw.Start();
var tasks = new Task[_queue.Count];
for (var i = 0; i < _queue.Count; i++)
{
tasks[i] = Task.Run(async () =>
{
//do the operation
_queue.TryDequeue(out var delay);
await Task.Delay((int)TimeSpan.FromSeconds(delay).TotalMilliseconds);
Console.Write($"{delay},");
});
}
await Task.WhenAll(tasks);
sw.Stop();
Console.WriteLine($"Total Time consumed: {sw.Elapsed}");
}
Sorry, I don't understand the difference between using the library and just creating the tasks on their own. The following also resolves in 22 seconds total.
In case the queue count is unknown , or let's say 1 million you may not be able to use your mentioned approach , requires a supercomputer :)
I have added more explanation to the beginning of the article as well, I hope it will be helpful to understand it better :)