Interop with synchronous code
When working with existing projects and introducing async code to the system, there will be points where synchronous and asynchronous code intersect. We have already seen some examples of how to handle this interop in this chapter. In this section, we will focus on that interop in both directions: sync calling async and async calling sync.
We will create a sample project with classes containing synchronous methods representing legacy code and another set of classes with modern
Let’s start by discussing how to consume
async methods in your legacy synchronous code.
Executing async from synchronous methods
In this example, we will be working with a .NET console application that gets a patient and their list of medications. The application will call a synchronous
GetPatientAndMedications method that in turn calls an async