You are previewing Pro Asynchronous Programming with .NET.
O'Reilly logo
Pro Asynchronous Programming with .NET

Book Description

Pro Asynchronous Programming with .NET teaches the essential skill of asynchronous programming in .NET. It answers critical questions in .NET application development, such as: how do I keep my program responding at all times to keep my users happy? how do I make the most of the available hardware? how can I improve performance?

In the modern world, users expect more and more from their applications and devices, and multi-core hardware has the potential to provide it. But it takes carefully crafted code to turn that potential into responsive, scalable applications.

With Pro Asynchronous Programming with .NET you will:

  • Meet the underlying model for asynchrony on Windows—threads.

  • Learn how to perform long blocking operations away from your UI thread to keep your UI responsive, then weave the results back in as seamlessly as possible.

  • Master the async/await model of asynchrony in .NET, which makes asynchronous programming simpler and more achievable than ever before.

  • Solve common problems in parallel programming with modern async techniques.

  • Get under the hood of your asynchronous code with debugging techniques and insights from Visual Studio and beyond.

  • In the past asynchronous programming was seen as an advanced skill. It's now a must for all modern developers. Pro Asynchronous Programming with .NET is your practical guide to using this important programming skill anywhere on the .NET platform.

    What you'll learn

  • How threads make asynchrony possible in .NET

  • The costs and benefits of different synchronization primitives

  • How to make the most of the async and await keywords for easier management of asynchronous operations

  • How to use an asynchronous model to scale processing across multiple cores

  • The different demands of IO and CPU bound processing

  • Debugging multithreaded code effectively

  • Who this book is for

    Pro Asynchronous Programming with .NET is for the .NET developer who wants to get more out of the platform. It's for the UI developer who finds their applications feel unresponsive. It's for the server-side developer who is struggling to scale their systems. It's for the developer who is being given more data to process and less time to do it in. Pro Asynchronous Programming with .NET is for people who want to solve problems but also understand how and why the solutions work.

    Table of Contents

    1. Title Page
    2. Dedication
    3. Contents at a Glance
    4. Contents
    5. About the Authors
    6. About the Technical Reviewer
    7. Acknowledgments
    8. CHAPTER 1: An Introduction to Asynchronous Programming
      1. What Is Asynchronous Programming?
      2. The Drive to Asynchrony
      3. Mechanisms for Asynchrony
      4. Thread Scheduling
      5. Threads and Resources
      6. Summary
    9. CHAPTER 2: The Evolution of the .NET Asynchronous API
      1. Asynchrony in the World of .NET 1.0
      2. Changes to Async in .NET 1.1
      3. Asynchrony in .NET 2.0
      4. Minor Changes in .NET 3.5
      5. Big Changes in .NET 4.0
      6. Summary
    10. CHAPTER 3: Tasks
      1. What Is a Task?
      2. Creating a Compute-Based Task
      3. Returning Data from a Task
      4. Error Handling
      5. Task Relationships
      6. Conclusion
    11. CHAPTER 4: Basic Thread Safety
      1. Asynchrony and Data
      2. The Interlocked Class
      3. Monitor: The Workhorse of .NET Synchronization
      4. Optimizing for Read
      5. A Semaphore Out of the Box
      6. Raising the Starting Gate: ManualResetEventSlim
      7. CountdownEvent: Simplifying Fork and Join
      8. Barrier: Rendezvous-Based Synchronization
      9. Crossing the AppDomain Boundary with WaitHandle
      10. Synchronization Is Not the Only Answer
      11. Conclusion
    12. CHAPTER 5: Concurrent Data Structures
      1. Simplifying Thread Safety
      2. Lazy<T>
      3. Concurrent Collections
      4. ConcurrentDictionary<K,V>
      5. ConcurrentQueue<T> and ConcurrentStack<T>
      6. ConcurrentBag<T>
      7. Blocking Collections
      8. Summary
    13. CHAPTER 6: Asynchronous UI
      1. UI Mechanics
      2. UI Threading Model
      3. Synchronization Context
      4. Data Binding
      5. WPF Dispatcher
      6. WinRT Dispatcher
      7. UI Timers
      8. WPF Freezable Components
      9. Too Much of a Good Thing
      10. Summary
    14. CHAPTER 7: async and await
      1. Making Asynchronous Programming Simpler
      2. What Do async and await Actually Do?
      3. Summary
    15. CHAPTER 8: Everything a Task
      1. TaskCompletionSource<T>
      2. Worked Example: Creating a Foreground Task
      3. Unit Testing and Stubbing Asynchronous Methods
      4. Building Task-Based Combinators
      5. Summary
    16. CHAPTER 9: Server-Side Async
      1. Natural Parallelism
      2. The Problem of I/O
      3. ASP.NET WebForms
      4. ASP.NET MVC
      5. ASP.NET Web API
      6. Windows Communication Foundation
      7. Summary
    17. CHAPTER 10: TPL Dataflow
      1. The Building Blocks
      2. Producer and Consumer Revisited
      3. Linking Blocks
      4. Shutting Down Gracefully
      5. Glue Blocks
      6. Asynchronous Blocks
      7. Summary
    18. CHAPTER 11: Parallel Programming
      1. What Is Driving the Need for Parallelism?
      2. Parallel Class
      3. PLINQ
      4. Summary
    19. CHAPTER 12: Task Scheduling
      1. ConcurrentExclusiveSchedulerPair
      2. Why Write a Task Scheduler?
      3. The TaskScheduler Abstraction
      4. Implementing a Custom Scheduler
      5. Unit Testing Custom Schedulers
      6. Summary
    20. CHAPTER 13: Debugging Async with Visual Studio
      1. Types of Multithreading Bugs
      2. The Limitations of Using Visual Studio for Debugging
      3. Multithreaded Visual Studio Debugging Basics
      4. Debugging Tasks
      5. Summary
    21. CHAPTER 14: Debugging Async—Beyond Visual Studio
      1. Memory Dumps
      2. Generating a Memory Dump
      3. Analyzing Memory Dumps
      4. Summary
    22. Index