Table of Contents
Preface;
Intended Audience;
How to Read This Book;
Conventions Used in This Book;
Using Code Examples;
Safari® Books Online;
How to Contact Us;
Acknowledgments;
Chapter 1: Introduction;
1.1 Asynchronous Programming;
1.2 What’s So Great About Asynchronous Code?;
1.3 What Is Async?;
1.4 What Async Does;
1.5 Async Doesn’t Solve Everything;
Chapter 2: Why Programs Need to Be Asynchronous;
2.1 Desktop User Interface Applications;
2.2 Web Application Server Code;
2.3 Silverlight, Windows Phone, and Windows 8;
2.4 Parallel Code;
2.5 An Example;
Chapter 3: Writing Asynchronous Code Manually;
3.1 Some Asynchronous Patterns Used in .NET;
3.2 The Simplest Asynchronous Pattern;
3.3 An Introduction to Task;
3.4 The Problem with Manual Asynchrony;
3.5 Converting the Example to Use Manual Asynchronous Code;
Chapter 4: Writing Async Methods;
4.1 Converting the Favicon Example to Async;
4.2 Task and await;
4.3 Async Method Return Types;
4.4 Async, Method Signatures, and Interfaces;
4.5 The return Statement in Async Methods;
4.6 Async Methods Are Contagious;
4.7 Async Anonymous Delegates and Lambdas;
Chapter 5: What await Actually Does;
5.1 Hibernating and Resuming a Method;
5.2 The State of the Method;
5.3 Context;
5.4 Where await Can’t Be Used;
5.5 Exception Capture;
5.6 Async Methods Are Synchronous Until Needed;
Chapter 6: The Task-Based Asynchronous Pattern;
6.1 What the TAP Specifies;
6.2 Using Task for Compute-Intensive Operations;
6.3 Creating a Puppet Task;
6.4 Interacting with Old Asynchronous Patterns;
6.5 Cold and Hot Tasks;
6.6 Up-Front Work;
Chapter 7: Utilities for Async Code;
7.1 Delaying for a Period of Time;
7.2 Waiting for a Collection of Tasks;
7.3 Waiting for Any One Task from a Collection;
7.4 Creating Your Own Combinators;
7.5 Cancelling Asynchronous Operations;
7.6 Returning Progress During an Asynchronous Operation;
Chapter 8: Which Thread Runs My Code?;
8.1 Before the First await;
8.2 During the Asynchronous Operation;
8.3 SynchronizationContext in Detail;
8.4 await and SynchronizationContext;
8.5 The Lifecycle of an Async Operation;
8.6 Choosing Not to Use SynchronizationContext;
8.7 Interacting with Synchronous Code;
Chapter 9: Exceptions in Async Code;
9.1 Exceptions in Async Task-Returning Methods;
9.2 Unobserved Exceptions;
9.3 Exceptions in Async void Methods;
9.4 Fire and Forget;
9.5 AggregateException and WhenAll;
9.6 Throwing Exceptions Synchronously;
9.7 finally in Async Methods;
Chapter 10: Parallelism Using Async;
10.1 await and locks;
10.2 Actors;
10.3 Using Actors in C#;
10.4 Task Parallel Library Dataflow;
Chapter 11: Unit Testing Async Code;
11.1 The Problem with Unit Testing in Async;
11.2 Writing Working Async Tests Manually;
11.3 Using Unit Test Framework Support;
Chapter 12: Async in ASP.NET Applications;
12.1 Advantages of Asynchronous Web Server Code;
12.2 Using Async in ASP.NET MVC 4;
12.3 Using Async in Older Versions of ASP.NET MVC;
12.4 Using Async in ASP.NET Web Forms;
Chapter 13: Async in WinRT Applications;
13.1 What Is WinRT?;
13.2 IAsyncAction and IAsyncOperation<T>;
13.3 Cancellation;
13.4 Progress;
13.5 Providing Asynchronous Methods in a WinRT Component;
Chapter 14: The Async Compiler Transformin Depth;
14.1 The stub Method;
14.2 The State Machine Struct;
14.3 The MoveNext Method;
14.4 Writing Custom Awaitable Types;
14.5 Interacting with the Debugger;
Chapter 15: The Performance of Async Code;
15.1 Measuring Async Overhead;
15.2 Async Versus Blocking for a Long-Running Operation;
15.3 Optimizing Async Code for a Long-Running Operation;
15.4 Async Versus Manual Asynchronous Code;
15.5 Async Versus Blocking Without a Long-Running Operation;
15.6 Optimizing Async Code Without a Long-Running Operation;
15.7 Async Performance Summary;