The State Machine Fueling Asynchronous Methods

When an asynchronous method executes, it may come across one or more await expressions. At that point in time, a dialogue is started with the object being awaited. This object is commonly referred to as the task, even though it doesn’t necessarily have to be a Task or Task<T> instance. We discuss the await pattern later on, also explaining how other types can be made awaitable.

What happens upon encountering a task being awaited depends on the current state of the task. Maybe the operation it represents has already been completed, allowing us to continue to execute the current method. However, most likely we’ll be unlucky and truly need to await the operation’s outcome before we can continue execution ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.