How can I wait for arrays of tasks of different types?

I have a pretty simple problem, but I can not find the answer anywhere.

Given that I have several arrays of tasks of different types, for example.

Task<Dog>[] dogTasks = GetDogTasks();
Task<Cat>[] catTasks = GetCatTasks();
Task<Fish>[] fishTasks = GetFishTasks();

What would be the best way WaitAll()for these tasks?

+4
source share
1 answer

WaitAllshould solve your problem. You have task arrays, so you must create one array from them:

var tasks = new List<Task>();
tasks.AddRange(dogTasks);
tasks.AddRange(catTasks);
tasks.AddRange(fishTasks);
Task.WaitAll(tasks.ToArray());
+4
source

Source: https://habr.com/ru/post/1618409/


All Articles