Implementing a TAP Method, Take One

Even though the easiest way to implement TAP methods is by using the new async modifier on a method declaration, we start off by examining a few handcrafted TAP methods. This will clearly illustrate the nature of the Task-based approach to signal the eventual completion of the method’s operation. Later in this chapter, you will learn how to simplify this by using asynchronous methods.

The key aspect to providing a TAP-based method is to return a Task or Task<T> object as soon as possible, which prevents the caller of the method from getting stuck. At a later point in time, this task gets set to let the caller know a result is available. Therefore, there are two sides to a task object: the receiving end (consumer) ...

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.