Asynchronous Programming in C# Explained (Task.Run, Task.WaitAll, Async and Await)

  Рет қаралды 113,379

Frank Liu

Frank Liu

Күн бұрын

Пікірлер: 109
@sriaz81
@sriaz81 4 жыл бұрын
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?
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
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 task is not blocking nthr the main task because they are running in parallel. So, they are essentially very closely related. Hence, I say that the difference between the two is in 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 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.
@sriaz81
@sriaz81 4 жыл бұрын
@@FrankLiuSoftware Thanks for the detailed answer. As per my knowledge, in async model, order of execution does not matter. It deals the problem of freezing or waiting when a long running task is executing itself. When we use await keyword, we are saying hey task please execute urself and when u r executing urself, give me the control back so that i can work on other things. So in this case time is switched b/w them for execution (they are not executing at the same time). When.long running task get completed it signals the main calling method that I am done. In case if we are doing async programming using task.run, then it pickup thread from thread pool to execute the task. While in parallel programming model, threads are created to execute the code and they all run in parallel
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
@@sriaz81 Yes Shahid, you are correct. I worded it in a confusing way. What I meant by "the order of executing" is that after the long running process finishes, something needs to be executed. I was referring to the call back process. With task.run, we have to specify a call back, yet with async and await, we achieve the same result without specifying a call back function. Parallel programming has multi threads run at the same time (same as async), but here we are mainly trying to resolve the shared resources problem: how can the multi threads access the same resource without causing conflicts.
@rajesh35hsp
@rajesh35hsp 3 жыл бұрын
async programming means long time taking tasks like getting input from user or reading from db, but not CPU intensive. While if you think of parallel programming it will be like doing some CPU intensive work processing millions of records.
@himanibhatnagar7439
@himanibhatnagar7439 Жыл бұрын
@@FrankLiuSoftware easiest explanation.. thanks
@Jonathan-bn8hb
@Jonathan-bn8hb 4 жыл бұрын
This is the clearest explanation video about asynchronous programming I've encountered. Thank you very much. You deserve a lot more subscribers. Keeps doing your thing man.
@expertreviews1112
@expertreviews1112 2 жыл бұрын
It means you haven’t seen enough videos
@os-channel
@os-channel 4 жыл бұрын
Great job, never saw a better tutorial concerning basics of Tasks
@kopilkaiser8991
@kopilkaiser8991 Жыл бұрын
You are absolutely brilliant. Months and browsing endlessly, you had finally made me understand the Task asynchronous topic. You earned a gold medal from me🎉
@NoOne-wf6hm
@NoOne-wf6hm 3 жыл бұрын
Best video on KZbin regarding Tasks for beginners. I still have to dig more into this until it makes absolute sense. Anyways: Thanks Frank.
@FrankLiuSoftware
@FrankLiuSoftware 3 жыл бұрын
Glad it was helpful!
@一江春水向东流-y6q
@一江春水向东流-y6q 3 жыл бұрын
this is really the best tutorial about async await c# for its simplicity and clearness i ever see, after reading so many microsoft documentation, i am still confused, now you save my ass, Thank you.
@eprice000
@eprice000 9 ай бұрын
Thanks for breaking it down in such an easy to understand way!
@andrewrayanit
@andrewrayanit 2 жыл бұрын
Thanks man. Sat late night and have given us great tutorial.
@julianocs87
@julianocs87 Жыл бұрын
Clear, concise explanation. Great video.
@naveenraj7503
@naveenraj7503 11 ай бұрын
Thanks Frank for giving a detailed explanation.
@adhivenkatesh3431
@adhivenkatesh3431 3 жыл бұрын
Hi Frank , Frankly telling its clean and very clear video , thanks for your effort and sharing to others.
@FrankLiuSoftware
@FrankLiuSoftware 3 жыл бұрын
You are welcome Adhi!
@kasuntkarunarathne
@kasuntkarunarathne 2 жыл бұрын
Thank you so much. Great explanation of Tasks, Async and await.
@cicbeats2956
@cicbeats2956 4 жыл бұрын
I consider myself as a slow learner, but this helped alot. THANK YOU!
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Glad that it is helpful!
@satishbhuktar2020
@satishbhuktar2020 2 жыл бұрын
How your awaiter.GetResult( ) is providing value.. it's return type is void.??.
@salaheddineelkhalifa8762
@salaheddineelkhalifa8762 3 жыл бұрын
Hello Man, You saved my Day you nailed it. Many thanks !
@FrankLiuSoftware
@FrankLiuSoftware 3 жыл бұрын
Glad that it is helpful!
@marlonbraga
@marlonbraga 2 жыл бұрын
Thanks Liu. This video help me so much
@LesibaPhokela
@LesibaPhokela 4 жыл бұрын
Thank you Frank, you gave a best example ever.
@Nicetrycutiepie
@Nicetrycutiepie 3 жыл бұрын
best explanantion and clean and simple to understand,, i just liked it very well...
@cloudguy4192
@cloudguy4192 3 жыл бұрын
Thank you for posting the video!
@FrankLiuSoftware
@FrankLiuSoftware 3 жыл бұрын
Thank you for watching!
@ukii261
@ukii261 3 жыл бұрын
Thanks a bunch! Helped me out a lot.
@vindjedouatchomba7742
@vindjedouatchomba7742 3 жыл бұрын
Thanks Frank Liu!! Great tutorial!
@FrankLiuSoftware
@FrankLiuSoftware 3 жыл бұрын
You are welcome!
@jimbroiles6905
@jimbroiles6905 2 жыл бұрын
Thank you for the clear explanation of the basics of asynchronous programming. I appreciate the way you that start with the basic concept and use very simple examples. Then additional concepts build on top off the previous ones, which builds our understanding step by step. It is an excellent approach to teaching. I learned everything I need to clear my understanding and go forward with correct implementations of asynchronous programming in C#. Many other tutorials on this topic should stop and learn from this one. Focus on teaching the concepts and implementation in simple, clear terms and quit trying to show how good you are at writing code. Many of us get lost in the complexity code you are trying to use as an example. It is a waste of time because the example is too hard to follow (Tim Corey please pay attention). I look forward to viewing more of your content. Subscribed.
@olgaliuft5607
@olgaliuft5607 4 жыл бұрын
You are a great teacher! Thank you for sharing these videos
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Thank you Olga!
@jayronthompson2562
@jayronthompson2562 Жыл бұрын
This is an amazing explanation.
@MasoudSamimi
@MasoudSamimi 4 жыл бұрын
you are great teacher , it was so clear
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Thank you so much!
@hiderr6805
@hiderr6805 5 жыл бұрын
Thank you man! You definateely need more subscribers huh (EDIT: For a moment at the begining i thought it's a joke (those houses lol))
@FrankLiuSoftware
@FrankLiuSoftware 5 жыл бұрын
C# in a home buyer's mind. LOL!
@hiderr6805
@hiderr6805 5 жыл бұрын
@@FrankLiuSoftware lol
@hiderr6805
@hiderr6805 5 жыл бұрын
@@FrankLiuSoftware xD
@tamilstudent1
@tamilstudent1 4 жыл бұрын
Such a calm explanation. Thanks.
@arborinfelix
@arborinfelix 2 жыл бұрын
This was a real good and clear tutorial.
@trustingod0
@trustingod0 9 ай бұрын
Hi Frank Liu, Thanks alot for the video. However I have a little question. What is the difference between Concurrency and Asynchronous?
@FrankLiuSoftware
@FrankLiuSoftware 9 ай бұрын
Check out my answer here: frankliucs.com/async-vs-parallelism-in-c
@trustingod0
@trustingod0 9 ай бұрын
@@FrankLiuSoftware Appreciate you putting the link for additional clarity. But I still don’t understand why we have all of these wonderful ways of making a Task run asynchronously with the ability to await other tasks until they are finished but I can’t think of any use cases where this is applicable except for database and file operations.
@akshaydubey.57.a75
@akshaydubey.57.a75 15 күн бұрын
thanks for this short & sweet
@amolpawale1657
@amolpawale1657 3 жыл бұрын
Very well explained. 🔥🔥🔥🔥
@bioanu
@bioanu 3 жыл бұрын
What is the reason you introduce the last function Test? I run the example using static async Task Calculate1_2() directly and the result is the same as using Test function.. What is the difference? Why do you introduce so many functions?
@Nicetrycutiepie
@Nicetrycutiepie 3 жыл бұрын
just brilliant explanation bro cheers.
@ЄгорШамрай
@ЄгорШамрай 4 жыл бұрын
Thanks for lesson!Can you make more videos about asynchronous programming or concurrency in C#?
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
It was my plan to do a series of that. But I am still planning. Not sure which one will go next.
@santoshmandal6805
@santoshmandal6805 2 жыл бұрын
Awesome............Well structured examples.
@hardikbhatt6976
@hardikbhatt6976 Жыл бұрын
Very very nice explanation
@Samuel-lm1wb
@Samuel-lm1wb 7 ай бұрын
Awesome work! Thank you
@niroshanmanoharan4295
@niroshanmanoharan4295 4 жыл бұрын
Thank you very much for your simple and clear explanation. May God Bless you!
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Thank you sir! May God bless you too!
@nmarks
@nmarks 2 жыл бұрын
Beautiful explanation.
@BitcoinBabu369
@BitcoinBabu369 4 жыл бұрын
Simply superb explanation. 🙏
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Glad that it helps.
@242hiran
@242hiran 4 жыл бұрын
Very calm and clear explanation. Thank you indeed Frank #maestro
@ofercarmeli6508
@ofercarmeli6508 5 жыл бұрын
Very good demo. Thanks!!!
@kanhamunjal759
@kanhamunjal759 4 жыл бұрын
Very well explained. Thank you Frank !
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
You are very welcome!
@MrSK168
@MrSK168 2 жыл бұрын
Thanks for sharing!!!
@EraZz187
@EraZz187 4 жыл бұрын
very good and clear explanation !!!
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Thank you Eraz!
@shuvbhowmickbestin
@shuvbhowmickbestin 2 жыл бұрын
what's a GetAwaiter()
@ma8892
@ma8892 2 жыл бұрын
Hi Frank Liu. Nice Video :). In the end you are creating a Test() - method with "async static void Test()". Is this a misstake? Since the general advice is to avoid "async void" for async methods, other than for event handlers.
@alijohn198
@alijohn198 Жыл бұрын
love this video ❤
@ramganapathy3298
@ramganapathy3298 3 жыл бұрын
Nice video. However, in your Calculate1_2 () method, you have the method signature as, "async static void Calculate1_2 ()". It will cause deadlocks. Instead, it should be, "async static Task Calculate1_2 ()".
@FrankLiuSoftware
@FrankLiuSoftware 3 жыл бұрын
That is correct. It is correct to use Task. KZbin doesn't allow you to fix a video once it is uploaded.
@avectresormt
@avectresormt 3 жыл бұрын
clean explaination
@robiesun3713
@robiesun3713 4 жыл бұрын
You helped me a lot. thanks for this video :)
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
You are very welcome!
@Ramboo339
@Ramboo339 4 жыл бұрын
Do you have an example with web api?
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
What exactly you want to see about web api? I am planning my tutorials, you are welcome to give suggestions! Thanks!
@Ramboo339
@Ramboo339 4 жыл бұрын
Using Asynchronous and synchronous methods for a web api weather app or news feed app for example
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Let me think about it! Thank you so much!
@UrvishKathiriya
@UrvishKathiriya 4 жыл бұрын
@@FrankLiuSoftware Yes, I'd love to see that. A video on Web API async await will help a lot. Thanks. :-)
@mdabuzar2130
@mdabuzar2130 4 жыл бұрын
Hi Frank, hope you are doing great. Could you please help me on how to process thousands of records in c#. Each record call a service to get some other details based on record id. Currently I am using paralell.foreach and it process 10000 record in an hour. Please suggest me how can I improve performance by 50%.
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Hi Md, the method you shall use depends on many factors. For example, the nature of the records you are processing, the way you are processing each record... I would do lots of comparisons and profiling. Have you tried without parallelism? How much time did that take? Have you tried partitioning the data before you do the parallel foreach? Just in case, don't forget to see if there are ways to improve the processing of each record.
@jorgesolano7060
@jorgesolano7060 5 жыл бұрын
Nice video man, thanks!!
@raunaksingh6050
@raunaksingh6050 5 жыл бұрын
thanks a lot, please upload more...
@markprescher
@markprescher 4 жыл бұрын
Great video!
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Thank you Mark!
@anandtiwari4723
@anandtiwari4723 3 жыл бұрын
thanks for this wonderful video :)
@FrankLiuSoftware
@FrankLiuSoftware 3 жыл бұрын
You are welcome!
@watchaccount
@watchaccount 4 жыл бұрын
You did not exaplain the last part. changing return value to Task.
@leozhang1340
@leozhang1340 4 жыл бұрын
讲得好!优秀👍👍
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
谢谢!很高兴帮助到你!
@一江春水向东流-y6q
@一江春水向东流-y6q 3 жыл бұрын
@@FrankLiuSoftware 技术很棒,英文说的也非常美式,我几乎听不出你的口音
@zaffarullah_bhutto
@zaffarullah_bhutto 4 жыл бұрын
Thank you man
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
You are welcome!
@poojanaidu2396
@poojanaidu2396 3 жыл бұрын
Screen is not clear
@fredrikterent8697
@fredrikterent8697 5 жыл бұрын
Great!
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Thank you!
@yz2039
@yz2039 4 жыл бұрын
Thank you! Xiexie
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
不客气!
@БориславБорисов-я2ы
@БориславБорисов-я2ы 5 жыл бұрын
Clearly!
@anushaaladakatti4145
@anushaaladakatti4145 4 жыл бұрын
Good explanation, could have been a little faster
@VarunKumar-qd5wl
@VarunKumar-qd5wl 4 жыл бұрын
en le Aladakatii, Heng idi?
@FuzzyDPozzy
@FuzzyDPozzy 4 жыл бұрын
9.32 was the reason i quit the tutorial. you should have kept it simple
@FrankLiuSoftware
@FrankLiuSoftware 4 жыл бұрын
Thank you! I like constructive comments! Appreciated!
@ВладимирСоколовский-щ1ы
@ВладимирСоколовский-щ1ы Жыл бұрын
#coding
@_NguyenManhToan_
@_NguyenManhToan_ Жыл бұрын
❤❤❤❤❤q
Delegates in C# - Explained with Simple Analogy
22:16
Frank Liu
Рет қаралды 10 М.
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
That's NOT How Async And Await Works in .NET!
12:25
Codewrinkles
Рет қаралды 29 М.
What are ASYNC and AWAIT in C#? Asynchronous Programming Tutorial
18:34
When You Shouldn't Use Await Async in .NET
7:51
Nick Chapsas
Рет қаралды 54 М.
Javascript Promises vs Async Await EXPLAINED (in 5 minutes)
5:50
Roberts Dev Talk
Рет қаралды 624 М.
C# Async Programming - Part 1: Conceptual Background
29:49
Rainer Stropek
Рет қаралды 67 М.
Learn Any Programming Language In 3 Hours!
22:37
Code With Huw
Рет қаралды 635 М.
8 await async mistakes that you SHOULD avoid in .NET
21:13
Nick Chapsas
Рет қаралды 317 М.