I have two async mehotds that not directly related to one another (they do both write out though).. and i don't want either to block the efficiency of the other..
If i place one of the activities in a set of tasks like this:
var list = new List<Task>();
foreach (var t in things)
{
list.Add(My.MethodAsync(t)); // method returns Task
}
await Task.WhenAll(t);
I know that it will not block, and potentially run in parallel..
If i another async method though though:
var list = new List<Task>();
foreach (var t in things)
{
list.Add(My.MethodAsync(t)); // method returns Task
}
foreach (var t in things)
{
await My.OtherAsync(t)); // method returns Task
}
await Task.WhenAll(t);
The Task.WhenAll() needs to wait for the second foreach to complete...
Therefore, is something like this possible / recommend?
var allTasks = new List<Task>();
foreach (var t in things)
{
allTasks.Add(My.MethodAsync(t)); // method returns Task
allTasks.Add(My.OtherAsync(t)); // method returns Task
}
await Task.WhenAll(t);
Having typed this out, even though the tasks themselves are independent, it would be nice i guess if an error was raised if both do not output.. hmm
question still stands though ;)