Why Asynchronous programming?

Because by default code works synchronously which runs everything on a same thread and can block the main thread.

Asynchronous programming however runs the divided and runs the code on different threads and not blocking the main thread.

In Asynchronous programming, async and wait keywords are used together.

Asynchronous programming in .Net has evolved over time, for example from Threading and Background Worker to Task Parallel Library and Async and Await (pauses execution of a particular method while fetching the result ).

Where can we use asynchronous programming?

For communication – I/O operations:-

  1. Disk
  2. Memory
  3. Web/Api
  4. Database

How to convert synchrnous code to asynchronous?

  1. Add async keyword to methods
  2. Add await keyword inside method to
  3. Avoid async method with void return type unless working with event handler.
    1. Change void to Task