In this post I want to summarize and collect some informations about Asynchronous Programming in C#. This topic is well documented from Microsoft.

A synchronous method call can result in a stucking program execution. An asynchronous method call in contrast, will return control back to the caller of the method and so the program can execute the next instructions without waiting to first complete the called method.

Async methods are intended to be non-blocking operations. An await expression in an async method doesn’t block the current thread while the awaited task is running. Instead, the expression signs up the rest of the method as a continuation and returns control to the caller of the async method.

The async and await keywords don’t cause additional threads to be created. Async methods don’t require multithreading because an async method doesn’t run on its own thread. The method runs on the current synchronization context and uses time on the thread only when the method is active. You can use Task.Run to move CPU-bound work to a background thread, but a background thread doesn’t help with a process that’s just waiting for results to become available.


In the following post for example, I will use the Async APIs to download a file from an Azure Storage Account share asynchronously.





Links

Asynchronous Programming Model (APM)
https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/asynchronous-programming-model-apm

Asynchronous programming with async and await
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/

Task asynchronous programming model
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/task-asynchronous-programming-model

async (C# Reference)
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/async

volatile (C# Reference)
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile