Categories
.NET C#

async/await: Why don’t use Task.Wait()?

In short explained why you should never use Task.Wait() to wait for an asynchronous task to complete from a synchronous context.

The Wait() method always returns an AggregateException if an error occurs within the task execution.

It would be hard to handle the real exception which is wrapped within the AggregateException.

Use GetAwaiter().GetResult() instead. It will return the real exception.

Leave a Reply

Your email address will not be published. Required fields are marked *