Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Async in C# 5.0
Preface
Intended Audience
How to Read This Book
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
1. Introduction
Asynchronous Programming
What’s So Great About Asynchronous Code?
What Is Async?
What Async Does
Async Doesn’t Solve Everything
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
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
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
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
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
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
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
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
10. Parallelism Using Async
await and locks
Actors
Using Actors in C#
Task Parallel Library Dataflow
11. Unit Testing Async Code
The Problem with Unit Testing in Async
Writing Working Async Tests Manually
Using Unit Test Framework Support
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
13. Async in WinRT Applications
What Is WinRT?
IAsyncAction and IAsyncOperation<T>
Cancellation
Progress
Providing Asynchronous Methods in a WinRT Component
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
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
About the Author
Copyright
← Prev
Back
Next →
← Prev
Back
Next →