A Primer to await Expressions

Asynchronous methods contain one or more await expressions. If no await expressions are present in the method, a compiler warning is generated telling the method will execute synchronously under all circumstances, questioning why the method was declared using the async modifier to begin with. Figure 31.20 shows this warning.

Image

FIGURE 31.20 Asynchronous methods can complete synchronously.

await expressions provide points in an asynchronous method body where the method can be suspended and resumed. Upon hitting an await expression, the compiler-generated code first evaluates the operand, which we referred to as the awaited ...

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.