Closed lindexi closed 2 years ago
The initial await is necessary for the case where RunAsync
itself fails (say because the dispatcher's thread no longer exists). In that case, the lambda never runs, so the taskCompletionSource
never completes its Task. The original version propagates the exception from RunAsync. The proposed version would hang.
@oldnewthing Thank you.
I found the code in UI-thread-task-await-from-background-thread.md
It will await
dispatcher.RunAsync
and then await thetaskCompletionSource.Task
. But it seems unnecessary to await twice.How about this code: