I have a Web API controller that does the following:
public async Task<Result> Post([FromBody] MyBody postBody)
{
// fire tasks
var doSomethingTask = DoSomethingMethod();
var doSomethingTask2 = DoSomethingMethod2();
tasks.Add(doSomethingTask);
tasks.Add(doSomethingTask2);
Task.WaitAll(tasks.ToArray()); //line in question
//do something async with results of these tasks
await DoSomethingAsyncWithResults(doSomethingTask.Result,doSomethingTask2.Result);
}
Now my question is in the above code should I actually be using
await Task.WhenAll(tasks.ToArray());
and what benefit - if any - would I see if I did that? Baring in mind this is a Web API controller so there is no UI to this application it's just getting called asynchronously from the frontend.
In my live environment there could be maybe 5 instances of this running, serving the front end. would locking up this method prevent it from responding to other requests?