Async Sample: Asynchronous Programming with Async and Await
This sample is a WPF application written in Visual Basic from the Asynchronous progamming with async and await in Visual Basic tutorial. The topic gives an overview of asynchronous programming, including when to use it and how to write an Async method. This sample contains an Async function that is used as an illustration.
Async and Await provide all the advantages of traditional asynchronous programming, but with much less effort from the developer. The compiler does the difficult work that the developer used to do, yet the code retains a logical structure that resembles synchronous code.
The example Async function in this sample (named
GetStringAsync) uses an HttpClient method to download the contents of a website.
The code for the MainWindow.xaml.vb file from this sample is included in the article.
This sample is written in Visual Basic and targets .NET 5.0 running on Windows. It requires the .NET 5.0 SDK.
Building the sample
To download and run the sample, follow these steps:
- Download and unzip the sample.
- In Visual Studio (2019 or later):
- On the menu bar, choose File > Open > Project/Solution.
- Navigate to the folder that holds the unzipped sample code, and open the C# project (.csproj) file.
- Choose the F5 key to run with debugging, or Ctrl+F5 keys to run the project without debugging.
- From the command line:
- Navigate to the folder that holds the unzipped sample code.
- At the command line, type