Author(s): Alex Davies
Edition: 1
Publisher: O'Reilly
Year: 2012
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
Asynchronous Programming
What’s So Great About Asynchronous Code?
What Is Async?
What Async Does
Async Doesn’t Solve Everything
Chapter 2. Why Programs Need to Be Asynchronous
Desktop User Interface Applications
An Analogy: The Cafe
Web Application Server Code
Another Analogy: The Restaurant Kitchen
Silverlight, Windows Phone, and Windows 8
Parallel Code
An Example
Chapter 3. Writing Asynchronous Code Manually
Some Asynchronous Patterns Used in .NET
The Simplest Asynchronous Pattern
An Introduction to Task
The Problem with Manual Asynchrony
Converting the Example to Use Manual Asynchronous Code
Chapter 4. Writing Async Methods
Converting the Favicon Example to Async
Task and await
Async Method Return Types
Async, Method Signatures, and Interfaces
The return Statement in Async Methods
Async Methods Are Contagious
Async Anonymous Delegates and Lambdas
Chapter 5. What await Actually Does
Hibernating and Resuming a Method
The State of the Method
Context
Where await Can’t Be Used
catch and finally Blocks
lock Blocks
LINQ Query Expressions
Unsafe Code
Exception Capture
Async Methods Are Synchronous Until Needed
Chapter 6. The Task-Based Asynchronous Pattern
What the TAP Specifies
Using Task for Compute-Intensive Operations
Creating a Puppet Task
Interacting with Old Asynchronous Patterns
Cold and Hot Tasks
Up-Front Work
Chapter 7. Utilities for Async Code
Delaying for a Period of Time
Waiting for a Collection of Tasks
Waiting for Any One Task from a Collection
Creating Your Own Combinators
Cancelling Asynchronous Operations
Returning Progress During an Asynchronous Operation
Chapter 8. Which Thread Runs My Code?
Before the First await
During the Asynchronous Operation
SynchronizationContext in Detail
await and SynchronizationContext
The Lifecycle of an Async Operation
Choosing Not to Use SynchronizationContext
Interacting with Synchronous Code
Chapter 9. Exceptions in Async Code
Exceptions in Async Task-Returning Methods
Unobserved Exceptions
Exceptions in Async void Methods
Fire and Forget
AggregateException and WhenAll
Throwing Exceptions Synchronously
finally in Async Methods
Chapter 10. Parallelism Using Async
await and locks
Actors
Using Actors in C#
Task Parallel Library Dataflow
Chapter 11. Unit Testing Async Code
The Problem with Unit Testing in Async
Writing Working Async Tests Manually
Using Unit Test Framework Support
Chapter 12. Async in ASP.NET Applications
Advantages of Asynchronous Web Server Code
Using Async in ASP.NET MVC 4
Using Async in Older Versions of ASP.NET MVC
Using Async in ASP.NET Web Forms
Chapter 13. Async in WinRT Applications
What Is WinRT?
IAsyncAction and IAsyncOperation
Cancellation
Progress
Providing Asynchronous Methods in a WinRT Component
Chapter 14. The Async Compiler Transform—in Depth
The stub Method
The State Machine Struct
The MoveNext Method
Your Code
Transforming Returns to Completions
Get to the Right Place in the Method
Pausing the Method for the await
Resuming after the Await
Completing Synchronously
Catching Exceptions
More Complicated Code
Writing Custom Awaitable Types
Interacting with the Debugger
Chapter 15. The Performance of Async Code
Measuring Async Overhead
Async Versus Blocking for a Long-Running Operation
Optimizing Async Code for a Long-Running Operation
Async Versus Manual Asynchronous Code
Async Versus Blocking Without a Long-Running Operation
Optimizing Async Code Without a Long-Running Operation
Async Performance Summary