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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.