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.


FIGURE 31.28 Compiler error when marking Main as async.

When you think about it, ...

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.