Open 0liver opened 1 year ago
I can't really answer the question, but this may be equivalent for your code base and doesn't cause a warning:
Task[] tasks = CreateTasks();
await Task.WhenAny(tasks);
foreach (var task in tasks)
Console.WriteLine(await task);
This has the added benefit that if you do something with the results that takes non-trivial time in the foreach
then in the worst case this will take as much time as the WhenAll()
code, but can be quicker if the slowest task is not the first one.
Good to see you, @Piedone! Thanks for the suggestion - nice hack. Actually, using await task
instead of task.Result
will work just as well when using Task.WhenAll()
- which is more expressive and less surprising, I guess. But the idea is interesting!
We have several occurrences of the following pattern:
The above code will generate an AsyncFixer02 warning for
task.Result
. This seems to be not necessary, because thetask
will already be completed at this point.What is the expected fix to this? I'm tired of suppressing the warning for every such place in our code.