Getting ready

What could be the use of a void return type in asynchronous methods? Generally, void is used with event handlers. Just bear in mind that void returns nothing, so you can't wait for it. Therefore, if you call a void return type asynchronous method, your calling code should be able to continue executing code without having to wait for the asynchronous method to complete.

With asynchronous methods that have a return type of Task, you can utilize the await operator to pause the execution of the current thread until the called asynchronous method has completed. Keep in mind that an asynchronous method that returns a type of Task basically does not return an operand. Therefore, if it was written as a synchronous method, it would be a void return type method. This statement might be confusing, but it will become clear in the following recipes.

Finally, asynchronous methods that have a return statement have a return type of TResult. In other words, if the asynchronous method returns a boolean, you would create an asynchronous method with a return type of Task<bool>.

Let's start with the void return type asynchronous method.

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

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