DEV Community

Discussion on: Faster & Easier Multi-Treading in batch processing with "Auto Fuel Concurrent Queue"

Collapse
dk profile image
Dunning-Kruger

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}");
    }
Collapse
alialp profile image
Ali Alp Author

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 :)

Collapse
alialp profile image
Ali Alp Author • Edited

I have added more explanation to the beginning of the article as well, I hope it will be helpful to understand it better :)