Return types of asynchronous functions
In asynchronous programming, the async
methods can have three possible return types. These are:
void
Task
Task<TResult>
We will have a look at each return type in the following recipe.
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 ...
Get C# Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.