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 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.