Asynchronous Programming in C#
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.
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.
Asynchronous Programming Model (APM)
Asynchronous programming with async and await
Task asynchronous programming model
async (C# Reference)
volatile (C# Reference)
In the following post I will use the Async APIs to download a file from an Azure Storage Account share asynchronously.