Asynchronous Programming in .NET 4.5 (async and await)

  Рет қаралды 140,226

Michael Kennedy

Michael Kennedy

Күн бұрын

Пікірлер: 139
@mikeckennedy
@mikeckennedy 5 жыл бұрын
Hi folks. If you're enjoying this presentation, I also have a 5-hour course in Python covering Python's equivalent async and await as well as more. Check it out at training.talkpython.fm/courses/explore_async_python/async-in-python-with-threading-and-multiprocessing
@Euquila
@Euquila 8 жыл бұрын
VB programmer here. I just switched from .net 4.0 to 4.5 and wanted to learn about async and await. I found your video exceptional. You really have a knack for teaching!
@LucasBatistussi
@LucasBatistussi 12 жыл бұрын
Wow! This is the best "tutorial" about asynchronous programming I ever saw! Finally I understood what asynchronous tasks are and differences with parallel approach. Keep doing this kind of great work! Congratulations! Favorited.
@AlanDias17
@AlanDias17 10 жыл бұрын
Best explanation I've ever found. We admire your work, dedication and competence.
@mikeckennedy
@mikeckennedy 10 жыл бұрын
Thank you!
@ValiRossi
@ValiRossi 6 жыл бұрын
I agree. Good job.
@magnusdeus123
@magnusdeus123 8 жыл бұрын
Just halfway through your video Michael and have to express my gratitude. You've explained this subject much clearer than so many other instructors whose I've tried to follow; especially even those on some huge, well-funded, training sites. Thank you, particularly, for explaining the little bit about Tasks in the beginning - so many tutorials either seem too dated; keen on teaching C# 3.5 Thread-based programming patterns, or jump straight to async and await.
@mikeckennedy
@mikeckennedy 8 жыл бұрын
Thanks so much Ash!
@LouisWaweru
@LouisWaweru 2 жыл бұрын
@@mikeckennedy I agree, I was almost sad to see your more recent videos are on Python 😅
@mikeckennedy
@mikeckennedy 2 жыл бұрын
@@LouisWaweru thanks for the nice thoughts Louis.
@MattRothtauscher
@MattRothtauscher 8 жыл бұрын
So old but still gold. Thanks for super easy understanding in that topic with going into detail. It really helped me understanding all of it :)
@mikeckennedy
@mikeckennedy 8 жыл бұрын
+Matt Rothtauscher Thanks, glad it helped you grok it!
@mikeckennedy
@mikeckennedy 11 жыл бұрын
Yes totally. The same stuff you see here applies. You just cannot touch the UI elements from the background threads so 1. Gather what you need. 2. Kick off the bg work. 3. The async / await keyword should bring you back to the ui thread on completion, then update the UI elements.
@Fean9rz
@Fean9rz 10 жыл бұрын
I was having big problems finding a way to fix a bug in my logic. I had a while(true) { // stuff } and other code that had to be executed at the same time. This video with the async await Task.Delay(time), made my day!!! Thank very very much!
@pavansonty1
@pavansonty1 4 жыл бұрын
Great video. I went through lot of material/other videos. But couldnt exactly understand how async await works. Thanks a lot for clearing the confusions around async & await.
@mikeckennedy
@mikeckennedy 4 жыл бұрын
You're welcome. Thanks!
@dland2000
@dland2000 8 жыл бұрын
Great video. Really helpful. The Surface vs. iPad search was classic.
@danielschmid8530
@danielschmid8530 11 жыл бұрын
Holy, that's what I call in-depth! I have been using the Thread and ThreadPool classes for a long time now and never really got around looking into that topic more thoroughly, but this has enlightended me so much! Everything is explained to the extent I need to update my applications using the await and async keywords and the Task-class, and get rid of the Thread and ThreadPool classes. Although I will profile the overhead Task has over ThreadPool, just for paranoia reasons. ;) Gonna share this.
@WoundedEgo
@WoundedEgo 10 жыл бұрын
I went to your website. What a great resource for us developers. Thanks!
@mikeckennedy
@mikeckennedy 12 жыл бұрын
Hi, Good question. You could use Parallel.ForEach but it would not have exactly the same effect. Using the await keyword on what is ultimately webclient.DownloadStringTaskAsyc() means we are just waiting on IO Completion ports. You'll see that the system doesn't actually create any more threads. ...
@OtRatsaphong
@OtRatsaphong 8 жыл бұрын
Wow, Great tutorial!! I finally understand how to use async & await. Thanks for the clear explanation.
@UBOATss
@UBOATss 11 жыл бұрын
First of all thank you for this information...2nd to sum it all up its like having your software invading multiple cpu's :) with 'continue with' you literally keep feeding the invasion and re-supply with instructions...this is awesome thanks again! i come from multi threading in java...this is very powerful stuff
@pratapkv2305
@pratapkv2305 10 жыл бұрын
Makes things crystal clear! Thanks Michael.
@yrajeshk532
@yrajeshk532 11 жыл бұрын
thanks Michael that was good introduction to the Asynchronous programming
@cvaldivia93
@cvaldivia93 10 жыл бұрын
Excellent video; thanks for sharing. You have a real gift for teaching.
@michor10
@michor10 7 жыл бұрын
This was a really well done presentation. Thank you for sharing.
@KCAbramson
@KCAbramson 8 жыл бұрын
Thanks for this. Wish i saw it back when it first came out! It's time to take the async thing more seriously like an adult coder.
@mikeckennedy
@mikeckennedy 8 жыл бұрын
+KC Abramson Thanks so much KC!
@nfskis
@nfskis 12 жыл бұрын
It's just Amazing. Very easy to understood what I have to study it!. Thanks you so much Michael. I love your video!! BEST C# Video ever!
@kevinpacheco8169
@kevinpacheco8169 10 жыл бұрын
This was amazing, thank you so much for putting this up!
@kirkbae9808
@kirkbae9808 9 жыл бұрын
I agree. Best explanation on this topic. Thank you very much.
@grog8164
@grog8164 7 жыл бұрын
Hey, great video! I have a question if I may. At 43:05 we see that we are on the main thread with the while true loop. If I understand correctly, because of async/await keyword on Task.Delay it mean that : "during the 200 ms of delay, the code execution is at exterior of the infinite loop, which makes the program not freezing and then (after 200ms) go back to your loop with your conditionnal SearchStats.downloadCount that is executed within few ms." If I remermber correctly you said that the await in from of something could be seems as a "continue" keyword allowing the code to proceed. But why the code goes exterior ?
@mikeckennedy
@mikeckennedy 7 жыл бұрын
Thanks. Basically, the await delay pushes a callback onto the event loop and then releases the UI thread. So while it looks like it should totally freeze up the program but because it does the callback + releases the thread each time through the loop all is well.
@mikeckennedy
@mikeckennedy 11 жыл бұрын
Thanks Daniel! You're most welcome. I appreciate the feedback. :)
@DJDoena
@DJDoena 10 жыл бұрын
Question: at 46:45 you can see that your new method has an await in it. Wouldn't that mean that the calling method with the loop would still be waiting for every download to complete before starting the next?
@mikeckennedy
@mikeckennedy 10 жыл бұрын
Hi DJ, There are two loops. The first foreach loops starts ALL the downloads and adds them to a List. At this point they are all running. The while loop just pulls them out as they finish, but they have all been started prior to hitting the while loop with the await. Make sense?
@responsibleparty
@responsibleparty 8 жыл бұрын
Great explanation of these concepts. Of course, the "message pump" version of the multithreading causes some problems that you didn't address. For example, when you click the Search button, it will be possible to click it again while it is running. These are the types of issues I think can be tricky. Clearly, you'd need to prevent that somehow.
@brakes255
@brakes255 11 жыл бұрын
Thanks Michael, was cool. This is kind of an odd question..is there anyway for components in the WPF framework to work Asynchronously, such as when displaying a treeView that has many nodes attached to it that it will load the nodes one by one onto the screen instead of the entire mainwindow locking until the treeview has finished processing?
@thebeauti101
@thebeauti101 9 жыл бұрын
Thank you for a great tutorial Michael!
@amaterasu48
@amaterasu48 10 жыл бұрын
This was very informative and easy to understand. Thank you!
@mikeckennedy
@mikeckennedy 12 жыл бұрын
Hi, are you asking for visual studio theme or for the powerpoint stuff?
@claudiovalerio7253
@claudiovalerio7253 11 жыл бұрын
Great video, great features! For decompiling, I suggest "Just Decompile" by Telerik: free, light and it just does the job!
@mikeckennedy
@mikeckennedy 12 жыл бұрын
If we did a Parallel.ForEach, we'd have a thread tied up for each pending request in addition to just the network wait. So we would add some overhead. It wouldn't be computational overhead in this case, but realize that we are then tied to the thread pool which limits the number of threads (approx 20 / CPU in practice) and each one requires 1 MB stack space. So it'd be similar, but we do get some truly new benefits from this Task.WhenAny version. Cheers, @mkennedy
@ncaatrackstar
@ncaatrackstar 9 жыл бұрын
I loved your tutorial, but why didn't you use the 1st Task example when trying to demonstrate the async and await commands? It would be great to see a 1 to 1 comparison.
@apraveen25
@apraveen25 12 жыл бұрын
Excellent demo. Thank you very much. Can you check the link for demo code as its not working right now?
@gauravtemkar8524
@gauravtemkar8524 10 жыл бұрын
Great Video! Thanks for the cool stuff..! :) Keep up the good work
@K0nc3pt10n
@K0nc3pt10n 7 жыл бұрын
Excellent video! Very well explained.
@klue16
@klue16 11 жыл бұрын
Any plans in the future to continue this tutorial? Maybe covering best practices in a multitude of situations? Dos & don'ts, etc.
@mikeckennedy
@mikeckennedy 11 жыл бұрын
No immediate plans directly on this series, but we are adding about 6 hours on this to LearningLine: learninglineapp.com/schedule I can let you know when it's ready.
@klue16
@klue16 11 жыл бұрын
Michael Kennedy , thank you! Definitely signing up. :-)
@TheTrueSmitch
@TheTrueSmitch 8 жыл бұрын
Michael! Wonderful video however I was wondering about a few things. First of all I noticed in your web search example you only used await at the once part. My question for that part was since you only used that would the thread run all the other code besides the await or would it just run it asynchronously but not run other tasks on the same thread.
@ej2649
@ej2649 7 жыл бұрын
Thank you Michael! Really help! Good tutorial.
@mikeckennedy
@mikeckennedy 11 жыл бұрын
Sure, see the description of the video.
@mahensavale
@mahensavale 8 жыл бұрын
Great explanation Michael !
@mikeckennedy
@mikeckennedy 8 жыл бұрын
+Mahendra Savale Thank you!
@NickMaovich
@NickMaovich 11 жыл бұрын
Really nice explanations, examples, and code! Thank you a lot!
@dangnguyenvinhphuoc7206
@dangnguyenvinhphuoc7206 7 жыл бұрын
Hi Mchael, this is good video to learn about Async and await, I could I have a example code of the second part (download using async). Thanks,
@mikeckennedy
@mikeckennedy 7 жыл бұрын
Thanks. The only code I have still around is at s3.amazonaws.com/michael-kennedy/blog/asynchronous-programming-in-net-4-5-video/websearcher-final-async-await-kennedy-demo.zip Hope that works!
@mikeckennedy
@mikeckennedy 12 жыл бұрын
Thank you everyone!
@arpit280392
@arpit280392 8 жыл бұрын
Thanks a lot Micheal...very clear explanation.
@mikeckennedy
@mikeckennedy 8 жыл бұрын
+Arpit Jain You're welcome!
@mikeckennedy
@mikeckennedy 12 жыл бұрын
I'd be happy to, however, I'm not sure where it is anymore. :(
@ChinmayGadre
@ChinmayGadre 11 жыл бұрын
very succinct training on async and await!
@nikitashrivastava8800
@nikitashrivastava8800 9 жыл бұрын
Great work !!! will keep this forever for reference :)
@mikeckennedy
@mikeckennedy 9 жыл бұрын
+Nikita Shrivastava Thank you so much Nikita!
@mikeckennedy
@mikeckennedy 11 жыл бұрын
Hi. I didn't do anything special. This is just the theme of Win8 at the time - was running a dev preview of win 8.
@weima544
@weima544 7 жыл бұрын
Explained so clearly, thanks
@klue16
@klue16 11 жыл бұрын
Awesome tutorial!! Thank you so much; really helpful.
@mikeckennedy
@mikeckennedy 11 жыл бұрын
Thanks, glad you like it!
@mikeckennedy
@mikeckennedy 12 жыл бұрын
Thanks Omar. I updated the link in the comments for downloading the code.
@karenwoods8567
@karenwoods8567 9 жыл бұрын
Hi Mike, where do we download the source code used in this tutorial? Please advise. Thanks..great video btw
@lynndemarest1902
@lynndemarest1902 6 жыл бұрын
One word: Brilliant. Thank you. (OK three words.)
@mikeckennedy
@mikeckennedy 6 жыл бұрын
Thanks a bunch Lynn. Glad it was helpful. :)
@mikeckennedy
@mikeckennedy 11 жыл бұрын
Glad you liked it. Great analogy!
@rmzzz76
@rmzzz76 8 жыл бұрын
Thank you so much for the information.... While I think the Task functionality added with .NET 4.0 is intuitive and useful, the sync / await syntax and overall paradigm were a poor direction. C# has not aged very well.
@krishnakantsharma09
@krishnakantsharma09 10 жыл бұрын
Very nicely explained. Thanks :)
@a1689k
@a1689k 11 жыл бұрын
The code doesnt work.. The search always returns an empty list, no matter whatever you search, and how much ever you increase the "entire internet".. could be a minor bug in the parallel programming logic.. as I am new to it, cannot fix it.. can anyone help?
@mikeckennedy
@mikeckennedy 11 жыл бұрын
Hi. I just downloaded the code, recompiled it and ran it. Works fine. Try a common term like truck or something.
@varshacon
@varshacon 11 жыл бұрын
Hi Michael, could you please paste the link again, I don't find the link anywhere. Thanks.
@ahmxtb
@ahmxtb 11 жыл бұрын
Why 48:00 using .ToArray()? I think it's not needed.
@mikeckennedy
@mikeckennedy 12 жыл бұрын
You're welcome, thanks for saying so.
@mikeckennedy
@mikeckennedy 12 жыл бұрын
Check the source, just updated the download like to work.
@nileshdDeolikar
@nileshdDeolikar 4 жыл бұрын
I want to DataGrid.DataSource = dbcontext.selectcateroties(0, 1).ToList(); in task
@JoshYates
@JoshYates 10 жыл бұрын
Well explained. Thank you sir.
@mikeckennedy
@mikeckennedy 10 жыл бұрын
Thanks!
@kllbd
@kllbd 4 жыл бұрын
hey dude, what's this Windows version? :o I was looking for it, but I didn't find the right version.
@PythonBytes
@PythonBytes 4 жыл бұрын
Hi. I think that sweet OS is Vista. :) It wasn't that great but was OK. Looked good.
@vkg.codefactory
@vkg.codefactory 10 жыл бұрын
Nice presentation, where can I find the demo source code?
@vkg.codefactory
@vkg.codefactory 10 жыл бұрын
I got it, it is just mentioned in the bottom notes, sorry!
@JoshYates
@JoshYates 10 жыл бұрын
Vinod Kumar Gupta The link was broke. hmmm....unless it's a firewall issue.
@jayeshmodha
@jayeshmodha 11 жыл бұрын
Thank you sir, you have a great teaching skill
@IWIH90
@IWIH90 9 жыл бұрын
Thank you for the awesome tut.
@ranjithk842
@ranjithk842 6 жыл бұрын
Nicely explained!!! Thanks
@garyngzb
@garyngzb 12 жыл бұрын
what theme you use?
@varshacon
@varshacon 11 жыл бұрын
Link to source code for both projects please.
@ReductioAdAbsurdum
@ReductioAdAbsurdum 12 жыл бұрын
This is an interesting talk, but the motivation presented at the start is not relevant (free lunch is over). The `async` keyword doesn't make it any easier to parallelize computation for purposes of increasing CPU utilization on a multi-core machine. It mostly makes it easier to write code that waits on long processes without blocking out main thread, for purposes of app responsiveness.
@PaulSebastianM
@PaulSebastianM 11 жыл бұрын
Windows 8 with non-standard theme? How?
@ryanjackson0x
@ryanjackson0x 12 жыл бұрын
Can you share your slidedeck?
@NGUY0035
@NGUY0035 10 жыл бұрын
awesome explaination!
@mikeckennedy
@mikeckennedy 12 жыл бұрын
Thanks Lucas! Much appreciated.
@mikeckennedy
@mikeckennedy 12 жыл бұрын
Thanks Cuong!
@Yartch
@Yartch 12 жыл бұрын
Thanks, great video! This really cleared a lot up for me.
@ThugLifeModafocah
@ThugLifeModafocah 4 жыл бұрын
The Async vs Parallel (1) is real parallelism. Two or more processing cores taking tasks in parallel. The Async vs Parallel (2) is concurrency. There's no real parallelism, the tasks are processed one at a time, switching very fast, giving the impression of simultaneos processing, but it's not. So async can be either parallel or concurrent and it is a big improviment from serial processing.
@menakaramasamy8936
@menakaramasamy8936 11 жыл бұрын
This is amazing video. Thanks a lot.
@loam
@loam 5 жыл бұрын
5:40 - dude foresaw the future, AMD Threadrippers and others really did came out.
@mikeckennedy
@mikeckennedy 5 жыл бұрын
:)
@iElite6809
@iElite6809 10 жыл бұрын
Great video. You just earned yourself a like and a subscription from me!
@prosoftwebindia
@prosoftwebindia 9 жыл бұрын
Nice! Thank You.
@jmng9689
@jmng9689 12 жыл бұрын
Great work.
@somnath.sonawne
@somnath.sonawne 11 жыл бұрын
Excellent video !!!!!!!!
@ZackLoveless
@ZackLoveless 12 жыл бұрын
Great video, thanks!
@mikeckennedy
@mikeckennedy 12 жыл бұрын
Thanks Joe!
@pr0l0gix
@pr0l0gix 7 жыл бұрын
awesome!! thanks!!
@milanmladenovic
@milanmladenovic 12 жыл бұрын
Great video! Thanks
@voodark
@voodark 11 жыл бұрын
Thank you very much!!
@mikeckennedy
@mikeckennedy 12 жыл бұрын
Thanks, link updated!
@cuongdev
@cuongdev 12 жыл бұрын
the video's so good, thanks.
@swoyum
@swoyum 12 жыл бұрын
Informative !
@KavkkAZEcc
@KavkkAZEcc 8 жыл бұрын
Thanks for tutorial
@ipekb3039
@ipekb3039 9 жыл бұрын
Thank you sir.
@davidfreire3766
@davidfreire3766 9 жыл бұрын
good work ;)
@mikeckennedy
@mikeckennedy 12 жыл бұрын
Thanks!
@dannyc.8696
@dannyc.8696 10 жыл бұрын
bill gates disliked this video at 29:48
@evyngreenwood6108
@evyngreenwood6108 8 жыл бұрын
Nah, like always, the only time apple is more useful than windows is when the windows user fucks up.
@sujithpattambi
@sujithpattambi 7 жыл бұрын
No, he will not :) . It is typo "suface" instead of "surface"
@gitnomad
@gitnomad 9 жыл бұрын
Thanks.
Advanced C#: 15 Async & Await
18:45
Clint Eastwood
Рет қаралды 128 М.
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
The Latest Celebrity Tech Scam…
19:21
Linus Tech Tips
Рет қаралды 2,5 МЛН
Correcting Common Async/Await Mistakes in .NET - Brandon Minnick
1:00:11
NDC Conferences
Рет қаралды 167 М.
c# (Csharp) and .NET :- Difference between IEnumerable and IEnumerator.
13:39
.NET Interview Preparation videos
Рет қаралды 497 М.
The Biggest React Framework You've Never Heard of
20:29
Theo - t3․gg
Рет қаралды 51 М.
Parallel Programming in .NET and C# 4
26:04
Rainer Stropek
Рет қаралды 77 М.
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.