Chapter 5. Writing asynchronous code

This chapter covers
  • What it means to write asynchronous code
  • Declaring asynchronous methods with the async modifier
  • Waiting asynchronously with the await operator
  • Language changes in async/await since C# 5
  • Following usage guidelines for asynchronous code

Asynchrony has been a thorn in the side of developers for years. It’s been known to be useful as a way of avoiding tying up a thread while waiting for some arbitrary task to complete, but it’s also been a pain in the neck to implement correctly.

Even within the .NET Framework (which is still relatively young in the grand scheme of things), we’ve had three models to try to make things simpler:

  • The BeginFoo/EndFoo approach from .NET ...

Get C# in Depth, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.