Synchronous: Suppose I am assigned 4 tasks (the first task has a range of 4 seconds, the second task has a range of 2 seconds, the third task has a range of 5 seconds and the last one has only one second) then in synchronous programming the one I assign first that will be finished first, then the second one will start working. This is how all of them will run one after the other. Since I have assigned four tasks then in synchronous programming my time will take a total of 12 seconds (4s+2s+5s+1s). Here is the code for synchronous in c#,

 
static void Main(string[] args) {
  // Synchronous task
  Task1();
  Task2();
  Task3();
  Task4();
  Console.ReadLine();
}
 
public static void Task1() {
  Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Started task 1...");
  Task.Delay(4000).Wait();
  Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Completed task 1!");
}
 
public static void Task2() {
  Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Started task 2...");
  Task.Delay(2000).Wait();
  Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Completed task 2!");
}
 
public static void Task3() {
  Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Started task 3...");
  Task.Delay(5000).Wait();
  Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Completed task 3!");
}
 
public static void Task4() {
  Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Started task 4...");
  Task.Delay(1000).Wait();
  Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Completed task 4!");
}

Asynchronous: (āĻāĻ–āĻžāύ⧇āχ āϕ⧇āĻŦāϞ async āĻāĻŦāĻ‚ await āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻšā§ŸāĨ¤ āϝ⧇āĻ–āĻžāύ⧇ await in asynchronous methods in C# is essential because it allows the method to suspend its execution until the awaited operation completes, without blocking the calling thread. This is crucial for non-blocking, responsive, and efficient code in scenarios where you have long-running operations such as I/O-bound tasks or network requests. āϝāĻžāϰ āĻŦāĻžāĻ‚āϞāĻž āĻ•āϰāϞ⧇ āĻĻāĻžāρ⧜āĻžā§Ÿ, C#-āĻ āĻ…ā§āϝāĻžāϏāĻŋāĻ™ā§āĻ•ā§āϰ⧋āύāĻžāϏ āĻĒāĻĻā§āϧāϤāĻŋāϤ⧇ await āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻž āĻ…āĻĒāϰāĻŋāĻšāĻžāĻ°ā§āϝ āĻ•āĻžāϰāĻŖ āĻāϟāĻŋ āĻ•āϞāĻŋāĻ‚ āĻĨā§āϰ⧇āĻĄ āĻŦā§āϞāĻ• āύāĻž āĻ•āϰ⧇ āĻĒā§āϰāϤ⧀āĻ•ā§āώāĻŋāϤ āĻ…āĻĒāĻžāϰ⧇āĻļāύ āϏāĻŽā§āĻĒā§‚āĻ°ā§āĻŖ āύāĻž āĻšāĻ“āϝāĻŧāĻž āĻĒāĻ°ā§āϝāĻ¨ā§āϤ āĻĒāĻĻā§āϧāϤāĻŋāϟāĻŋāϕ⧇ āϤāĻžāϰ āĻ•āĻžāĻ°ā§āϝ āϏāĻŽā§āĻĒāĻžāĻĻāύ āĻ¸ā§āĻĨāĻ—āĻŋāϤ āĻ•āϰāϤ⧇ āĻĻ⧇āϝāĻŧāĨ¤ āĻāϟāĻŋ āĻāĻŽāύ āĻĒāϰāĻŋāĻ¸ā§āĻĨāĻŋāϤāĻŋāϤ⧇ āĻ…-āĻŦā§āϞāĻ•āĻŋāĻ‚, āĻĒā§āϰāϤāĻŋāĻ•ā§āϰāĻŋāϝāĻŧāĻžāĻļā§€āϞ āĻāĻŦāĻ‚ āĻĻāĻ•ā§āώ āϕ⧋āĻĄā§‡āϰ āϜāĻ¨ā§āϝ āĻ…āĻ¤ā§āϝāĻ¨ā§āϤ āϗ⧁āϰ⧁āĻ¤ā§āĻŦāĻĒā§‚āĻ°ā§āĻŖ

āϝ⧇āĻ–āĻžāύ⧇ āφāĻĒāύāĻžāϰ āĻĻā§€āĻ°ā§āϘ-āϚāϞāĻŽāĻžāύ āĻ•ā§āϰāĻŋāϝāĻŧāĻžāĻ•āϞāĻžāĻĒ āϝ⧇āĻŽāύ I/O-āĻŦāĻžāωāĻ¨ā§āĻĄ āϟāĻžāĻ¸ā§āĻ• āĻŦāĻž āύ⧇āϟāĻ“āϝāĻŧāĻžāĻ°ā§āĻ• āĻ…āύ⧁āϰ⧋āϧ āϰāϝāĻŧ⧇āϛ⧇āĨ¤) On the other hand, in an asynchronous program, if I am assigned 4 tasks (the first task has a range of 4 seconds, the second task has a range of 2 seconds, the third task has a range of 5 seconds and the last one has only one second) then in the asynchronous program all the tasks start at once, then the one with the lowest that one’s work is completed first, while the others also finish a little. In this way all the tasks are finished by the time it takes 5 seconds at the most. Whereas synchronous takes 12 seconds but asynchronous takes only 5 seconds. Here is the code for asynchronous in c#,

static void Main(string[] args) {
  // Asynchronous task
  Task5();
  Task6();
  Task7();
  Task8();
  Console.ReadLine();
}
 
public static async void Task5() {
  await Task.Run(() => {
    Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Task 5 starting...");
    Thread.Sleep(4000);
    Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Task 5 completed!");
  });
}
 
public static async void Task6() {
  await Task.Run(() => {
    Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Task 6 starting...");
    Thread.Sleep(2000);
    Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Task 6 completed!");
  });
}
 
public static async void Task7() {
  await Task.Run(() => {
    Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Task 7 starting...");
    Thread.Sleep(5000);
    Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Task 7 completed!");
  });
}
 
public static async void Task8() {
  await Task.Run(() => {
    Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Task 8 starting...");
    Thread.Sleep(1000);
    Console.WriteLine(DateTime.Now.ToLongTimeString() + " : " + "Task 8 completed!");
  });
  Console.WriteLine("Check all task exist or not!");
}

For youtube video help click here

For my video click here