I have two sets of Tasks, each with a different type of result:
IEnumerable<Task<T1>> set1 = GetTasksOfT1();
IEnumerable<Task<T2>> set2 = GetTasksOfT2();
Now I would like to wait for both sets on the same line, but I had to design set1 with cast:
await Task.WhenAll(set1.Select(p => p as Task).Concat(set2));
This is because I get this error if I do not use casting:
IEnumerable<Task<T1>>' does not contain a definition for 'Concat'
and the best extension method overload 'Queryable.Concat<Task<T2>>(IQueryable<Task<T2>>, IEnumerable<Task<T2>>)'
requires a receiver of type 'IQueryable<Task<T2>>'
It is obvious.
So, is there a way to use single WhenAll () without casting?
Edit: The inverse types T1 and T2 are important - I consume them after the expected tasks:
var t1Results = await set1;
var t2Results = await set2;
DoSomethingWithResults(t1Results, t2Results);
source
share