Declaring Asynchronous Methods

The declaration of an asynchronous method is easy and simply involves adding an async modifier. You can combine this modifier with other modifiers such as static, the accessibility modifiers, and so on. Figure 31.16 shows a couple of valid asynchronous method declarations.

Image

FIGURE 31.16 Asynchronous method declarations.

Notice how an Async suffix is added to the methods to conform with the TAP guidelines. This is merely a convention that isn’t checked by the compiler, but can be checked by code analysis tools.

A few restrictions apply to asynchronous methods. One is the set of allowed return types, restricted to ...

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.