Within the following query i would like to add:
-
Trace.WriteLine(i.Name) -
and get a count of tasks without an additional enumeration afterwards (without a separate
int count = tasks.Count())
Sample Query
var tasks = (
from i in items
where i.IsValid
orderby i.Priority
select i.GetTask())
.Take(100);
await TaskEx.WhenAll(tasks);
I know how to achieve that with subsequent/extra enumerations, but I was wondering how to do all that in one enumeration? It’s important because the i.IsValid operation is actually expensive and I would like to only call that once in order to do the filtering…
Given that you’re only taking 100 items anyway, I’d just use
ToListto force it to be in a list:Then you can iterate over them to trace them, easily get the count, and pass the list to
TaskEx.WhenAll.