Don't use async void methods

A common mistake about asynchronous programming in .NET Core and, more in general, in the whole .NET ecosystem, is to declare a method as async void. Indeed, when we declare a method as async void, we will not be able to catch exceptions thrown by the method. Furthermore, the Task type is used to capture the exceptions of the method and propagate them to the caller. In summary, we should always implement our async methods by returning the Task type when the method returns void, otherwise, we should return the  Task<T> generic type when the method returns a type.  Furthermore, the Task type is also useful when we want to notify the status of the operation to the caller: the Task type exposes the status of the operation through the following attributes: Status, IsCanceled, IsCompleted, and IsFaulted.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.48.135