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 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.