0

Consider the following code:

Task<bool> task = SomeAsyncOperation();

// Some more code in which the task might be awaited

return task.IsCompleted && !task.IsFaulted && task.Result;

Using .Result in an async method is generally discouraged, since it may lead to a deadlock. However, since here it will only be called if the task IsCompleted, I'd say it's safe to do it. Am I right?

Tao Gómez Gil
  • 1,770
  • 13
  • 31
  • 1
    The deadlock thing is likely not occurring (since the task is completed). But the boolean evaluation is likely to return false most of the time if the call to `SomeAsyncOperation` is not awaited. – lidqy May 16 '22 at 10:48

0 Answers0