No Asynchronous Main Method?

One key property of asynchronous methods is their early return while work is carried out. The returned Task or Task<T> object is used to track the completion of the operation, which is usually done using an await expression. To use an await expression, the containing method has to be declared as asynchronous as well. You may wonder what happens if asynchrony continues to spread up the invocation chain, all the way to the Main method. Figure 31.28 shows the error message that results when trying to mark the Main method as asynchronous.

Image

FIGURE 31.28 Compiler error when marking Main as async.

When you think about it, ...

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.