Simultaneous execution of asynchronous tasks: Task.Result and task.getawaiter (). Getresult () differences
When processing asynchronous methods, sometimes they need to execute them synchronously. However, there are two common methods in synchronous execution:
and, there are key differences between them. Task.Result
Task.GetAwaiter().GetResult()
task.wait and task.getawaiter (). Getresult () compare
and both allow the synchronous execution of asynchronous tasks. However, their abnormal processing mechanisms are different.
Pack any abnormality in, and Task.Wait
will directly throw the original abnormalities. Task.GetAwaiter().GetResult()
Task.Wait
Suggestion AggregateException
Task.GetAwaiter().GetResult()
better than . However, both methods should be avoided as much as possible, but should be preferred, because the first two may cause the exhaustion of the resource of dead locks and thread pools.
Different reasons Task.GetAwaiter().GetResult()
Task.Wait
The difference between the abnormal treatment of async/await
and
maintains its original blocking behavior and packs abnormalities in .
To directly cause abnormal dissemination, you can use. It should be noted that will check the task errors instead of blocking its execution. Task.Wait
The above is the detailed content of Task.Result vs. Task.GetAwaiter().GetResult(): What's the Difference in Synchronous Execution and Exception Handling?. For more information, please follow other related articles on the PHP Chinese website!