How to execute functions in parallel in C#?


When a user requests, I want to make several queries to the database and then display the response.
But if I use

await- Function1    
await- Function2  
await- Function3  
"склеить ответ функций и перевести в json"  
вывести ответ....  

then in fact these functions are executed one after another with the only difference that the process does not hang until there is no answer, unlike synchronous programming, but there is no multithreading.
How to make multithreading and that's when the answer will be received from all functions – call await?


Try it via Task.WhenAll :

Task first  = Function1();
Task second = Function2();
Task third  = Function3();

await Task.WhenAll(first, second, third);
Scroll to Top