I have a video on my YouTube channel regarding Asynchronous programming in C#. I will post the video at the end of this blog post. Today, someone asked a question in my channel and I thought I will share the answer here. Hope it helps a lot of more people.
He asked: “Hi Frank Liu, Thanks alot for the video. However I have a little question. Is there any difference in parallel vs async programming? If yes, then is this tutorial is for Parallel Programming or is it about async programming?”
Here is my answer:
“Hi Shahid, that is a great question! I am not sure if I can explain clearly in a comment, but I will try.
To understand what asych is, the easiest way is to think about what synch is: task1, task 2 and task 3 have to run in sequence in other words, they have to run synchronously. Whereas, if task 2 runs before task 1finishes, we call it asynchronous. Here, we are emphasizing the order of executing.
Then what is parallelism? Obviously, when two tasks are running at the same time, we say they are running in parallel. Here, we are not emphasizing the sequence, but that there are multiple activities at the same time.
However, if you think deeper. In asynchronous programming, there have to be at least two tasks, the main task carried on by the main thread, and the long running task. The long running task is not blocking the main task because they are running in parallel. So, the two topics are essentially very closely related.
Hence, I say that the difference between the two is in the emphasis. One is empathizing the order of execution can go out of sync, the other is emphasizing two or more tasks can run at the same time.
Because the emphasis is different, the problems the two are trying to resolve are different too. Asynchronous tries to resolve how to continue after the long running task, whereas Parallelism tries to resolve sharing resources/messages between the threads.
This video tutorial is more about async and less about parallelism because it deals more with how to continue after a long running task. However the two topics are closely related. I hope that helps!”
Here is the video: