Table of Contents

async/await

await is an asynchronous wait:

await operation();

The operation called after the await keyword is an “awaitable”. When execution reaches await:

Methods containing await must:

Awaitable expression types

An expression is awaitable if it is of a type that provides a specific set of properties.

The types Task and Task<T> are awaitable; you could also roll your own.

If you don't need a result immediately (so can call an operation asynchronously) but will need it by some future time, Task.Wait() is a blocking call that returns only when the asynchronous operation has completed.

Task<T>

Task<T> enables you to return a value (of type T) from an async method. The Task wrapper provides a reference to the awaited operation, allowing you to access the returned value when the asynchronous operation has completed.

Access to the returned value is provided by the Task.Result property; calling the property's get accessor also blocks the calling thread (equivalent to calling Task.Wait()).

See also

https://blog.stephencleary.com/2012/02/async-and-await.html