I have two tasks, and I wait them to be finished with
await Task.WhenAll
Can it be a problem to get after that the value directly by calling .Result
I am sure that the tasks are already finished.
`
Task<int> t1 = Task.FromResult(1);
Task<int> t2 = Task.FromResult(2);
await Task.WhenAll(t1, t2);
var uuu = t1.Result;
// or var uuu = await t1;
`
The problem is that visual studio set a VSTHRD103 Call async methods when in an async method warning.
I checked with sharplab and .Result version jit is a bit smaller.
Can I get any deadlock if I call .Result after that I already await them with Task.WhenAll?
There's no problem, as the tasks have already finished. This is a false positive which can be ignored.
If all tasks return the same result though, Task.WhenAll returns an array with the results:
var results=await Task.WhenAll(tasks);
The results are in the same order as the tasks that produced them
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With