Async/Await Webinar Series: Best Practices

See how to avoid common pitfalls in asynchronous code bases

 

Summary

Daniel Marbach shows how to avoid common pitfalls in asynchronous code bases.

Learn how to:

  • Differentiate between IO-bound vs CPU-bound work and how this relates to Threads and Tasks
  • Avoid serious production bugs as a result of asynchronous methods returning void
  • Opt-out from context capturing when necessary
  • Deal with synchronous code in the context of asynchronous code

About the webinar series

The 3-part series explores Async/Await best practices, Task Parallel Library and Message Pumps, how the NServiceBus V6 API update helps to avoid common Async/Await pitfalls and makes your code ready for asynchronous APIs in the cloud.

Definitions

"Async" and "await" are keywords introduced in C# 5 that make it easier for developers to write asynchronous code. Under the hood the C# compiler transforms `async` methods in such a way that whenever an asynchronous operation is "await"-ed, the current flow of control requests to be resumed when the "await"-ed task completes and immediately returns control to the caller of the "async" method.

"Async" and "await" allow developers to reap the benefits of asynchronous programming and stay as close to the familiar synchronous programming model as possible.

The Task Parallel Library (TPL) is a library in the .NET Framework that allows developers to add concurrency and parallelism to their applications without getting bogged down in low-level implementation details. The TPL automatically handles tasks such as managing the thread pool and adjusting the level of concurrency to best utilize the available hardware resources. The API pushes developers into thinking about high-level concerns such as partitioning work to exploit task and data parallelism inherent in the problem at hand instead of focusing on threads, locks and other concurrency primitives.

Software performance can be improved by avoiding blocking on long-running tasks such as Web requests or database queries. In asynchronous code a thread of execution starts a long-running operation and requests to be notified of its completion. This allows the thread to do other useful work while the long-running task is in progress, thus improving throughput and responsiveness.

Asynchronous programming APIs are often based on callbacks. Unfortunately control flow based on callbacks can quickly lead to code that is difficult to write, understand, and maintain.

  • Learn how to combine Async/Await and Task Parallel Library to create a message pump for a service bus.

    TPL & Message Pumps
  • See how the v6 API update helps to avoid common Async/Await pitfalls and makes code ready for asynchronous APIs in the cloud.

    NServiceBus v6 API Update

About the host

  • Daniel Marbach

    @danielmarbach

    Daniel Marbach is a Microsoft MVP for systems integration and a Solution Architect at Particular Software.