7 C# Async operations

 

This chapter covers

  • Learning the technology behind Asynchronous programs
  • Developing code to work asynchronously
  • Comparing values through the use of pattern matching
  • Using Records to define classes
  • Developing a timed "Diffuse the bomb" math project

Welcome to chapter 7, and welcome to the first big challenge. While the previous file system chapter included the first official advanced project, it was just the introduction to the second part of this book. With this chapter, we enter the world of Asynchronous programming. If we have ever heard about await and async, we have successfully encountered an asynchronous program in its natural habitat. However, if we are not yet familiar with these, we will not know what we could do with them or what advantages they offer. So, it is for that, that this chapter exists.

In this chapter's project, we will use async operations and pattern matching to develop a project that will prompt the user with a timed, randomly generated math question. Using asynchronous operations, we will be able to run a timer while simultaneously running our main logic throughout the entire process, from prompting the question to receiving the answer and comparing results.

7.1 The Central Processing Unit

7.1.1 How does asynchrony work on the CPU

7.1.2 Asynchrony versus multithreading

7.2 Asynchronous programming in C#

7.2.1 What is asynchronous programming in C#

7.2.2 Common Use cases and when to use

7.2.3 Overview of the asynchronous model

7.3 Pattern Matching

7.3.1 What is pattern matching

7.3.2 Pattern matching in C#

7.3.3 Types of patterns

7.4 Diffuse the bomb

7.4.1 The project

7.4.2 Our Algorithm

7.4.3 Source code

7.5 Summary

7.6 References