Why You Must Use Asynchronous Programming in C# | Deep Dive🚀 into Async/Await
Published in
5 min readSep 2, 2024
Asynchronous programming is a programming technique that allows a program to start a potentially long-running operation (like I/O tasks) and continue executing other code while waiting for the operation to complete.
In contrast, non-asynchronous (synchronous) programming will block the execution of further code until the operation finishes.
Key Concepts
- Synchronous Programming: Each task runs in sequence. When a task is initiated, the program waits for it to complete before moving on to the next task. This can cause delays and make the program unresponsive if a task takes a long time.
- Asynchronous Programming: Tasks can be initiated and executed concurrently. The program does not wait for a task to complete before moving on, allowing it to perform other operations in the meantime.
Let’s compare synchronous and asynchronous approaches with a simple example: fetching data from a web API.
Synchronous Example
In this example, the program will wait (block) until the data is fetched from the API before continuing: