Answer the question
In order to leave comments, you need to log in
Problem with Task.WhenAny does not start all tasks at once, How to solve?
I am writing an application in C# with async await, which loads data by url and parses.
Experimentally found out that 500 simultaneous tasks load my computer most efficiently.
I create a small list of 500 tasks and when I write Task.WhenAll(tasks) all tasks start at the same time and end when they have to. Rewrote it to Task.WhenAny(tasks) - I delete completed ones and add new ones up to 500 to keep 500 tasks constantly running. But more than 60 tasks are not launched at the same time. It turned out that Task.WhenAny starts tasks in turn with an interval of about 1 second.
Tell me how to write so that it works effectively, it’s very reluctant to return to threads.
VS2013 Update2 WPF C# .NET 4.5
Answer the question
In order to leave comments, you need to log in
In fact, Task.WhenAll also does not start all tasks in parallel, the tasks are executed in the ThreadPool and it is he who is responsible for launching the tasks. If you need to limit concurrency from above, you can use a similar solution: MSDN
How did you figure out that 500 tasks is the best option?
Meanwhile, Windows operates on threads, and the more threads are running, the more time it takes to switch between them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question