You can simply start both Task
s and then wait for both of them to complete:
Task lookupsTask = environment.LoadLookupsAsync(cancellationToken);
Task foldersTask = environment.LoadFoldersAsync(cancellationToken);
await lookupsTask;
await foldersTask;
A more efficient version of the same code would be to use Task.WhenAll()
:
await Task.WhenAll(lookupsTask, foldersTask);
If you want to do this for a collection of Task
s, not just two of them, you can fill a List<Task>
with all the Task
s and then await Task.WhenAll(tasksList)
.
One issue with this approach is that if more than one exception happens, you're only going to get the first one. If that's a problem for you, you can use something like what 280Z28 suggested.