Either this [advanced] concept is really simple or was it just explained in such a way that it seems very easy to use..... I'm really glad I found these videos. This concept is a game changer, for sure. I wish I would've found these years ago!
Great demo! NOTE: You'll want to create a new cancel token before calling the async because on the next try the token will still be canceled. CancellationTokenSource cts = null; // At declaration (top of class) ... // In the executeAsync_Click() method... cts = new CancellationTokenSource(); var results = await DemoMethods.RunDownloadAsync(progress, cts.Token); PrintResults(results); ... // In the cancelOperation_Click() method... if (cts != null) cts.Cancel();
Thank you Tim. You are one of the very few video creators with real passion for what you do and for teaching people. Your videos are done in perfect pace, you stop at important parts and explain them. Simply amazing!
Tim, if it weren't for you, I'd still be messing around with a console application that does nothing useful. Your videos are one of the greatest learning sources I've ever come across. You've taught me many essential things in C#. Great work. Other resources are nothing compared to what you provide (even for free!)
Honestly the best, most concise summary of a topic I find myself struggling with constantly. Excellent resource for software professionals and amateurs alike. Well done!
This was a great video. Understandable and informative. Thanks a lot. The hard thing is not how hard the problem is. The real problem is to explain it simply and easily, no matter how difficult it is. It's more difficult to simplify and make it understandable. This is what you doing your videos.
I was very confused between synchronous and asynchronous programming & how to use async/await keywords. This video cleared my all confusion. Thanks you so much.
Man I can’t believe how much I learned from your videos. I’ve gotten back into C# development for my job which involves a lot of automation. My tools are internal to our team, just basically making tools to automate a lot of mundane tasks that eat up our time. Can’t thank you enough for your help, you most definitely earned my sub
You are the best teacher to teach C# programming tutorials. I really understand your concepts in-depth as you explain with keeping everything in mind. Not too vague, or not too complex. Just enough spices to make the recipe (knowledge) tasty to consume! Aromatic and delightful. Please keep up the hard work. I pray for your wellbeing and may you be blessed with more success. InshaAllah 🤲❤. Lots of love from me brother.
I was having an awful time trying to make a bunch of legacy code I can't really change to run faster. Found your first video on async/await and managed to shave off a ridiculous amount of time. You are a life saver, thank you so much for your help!
Been struggling with creating a ASYNC fileDownloaded, but succeeded using CLASSES without using any threads, it works but the code was like spagetti, overlaps and overloads etc. So decided to revisit the code from last year and try to enhance my knowledge and using threads and tasks.. it worked to a certain point using Delegates and SafeData methods and invokes etc.. but still was not 100% something to be proud about, until I ran across your videos TIM.. thank you for the examples and level of detail and the download site.. AMAZING work.. and very much appreciated.
Everytime my lead dev asks me to do smthing confusing im like... "If theres a TimCorey for it im good". Today was cancelation tokens and logging. Cheers for saving my bacon again dude.
Hey Tim, great video. Correct me if I'm wrong, but I think calling Add method on List inside Parallel.ForEach can lead to thread related issues as List is not thread-safe (according to MS only public static members are thread-safe). It's necessary to employ synchronization techniques or use a concurrent collection to avoid any problems.
Great video again. It helped me clear in my mind the actual difference between Task.WhenAll and Parallel.ForEach. Hats off to you Tim. Thanks for breaking down tough things in easy to understand manner for us.
Both videos on Async / Await are awesome, from scratch to the advance with a visual touch. Wow you just open up my understanding of this topic. Bless you Tim Corey.
I'm watching the end of the progress bar part thinking "Wow, I can't wait to do this. I will have to re-watch this and follow along but I should be able to figure it out if I try." Tim Corey: 24:48 Seriously, though. This is explained extremely well. Thank you!
Thanks for the video! 1) suspend exceptions by using try catch is questionable practice 2) i would not use throw an exception to cancel the operation 3) if you want to cancel the operation do it in the beginning of the loop is better practice in this case due to hevy lifting is in web call
Hey Tim, I just finished Advanced Async course and to be honest, I learned so many things even though I have been working on c# for the last 8+ years . Keep up the good work
Just a few comments: 1) the CancelationTokenSource cannot be "reset" and a new one must be created for each use. 2) Parallel.ForEach uses multiple threads for each "chunk" of work, whereas the Task.WaitAll() method doesn't use threads. 3) In the Parallel.ForEach case, you might be able to use a ContinueWith to add the common progress handling as each download finishes (I haven't tested this, and it probably isn't a recommended technique).
Another outstanding presentation. Thank you for the methodic progression as you introduce more complex topics. You really make C# simple. I appreciate the section on token cancellation source, the Parallel.foreach overview, and the use of async to keep the UI responsive. The Progress logic was also helpful and a little cleaner than my own.
Hey, did you delete your last comment about your comments being deleted? I saw it but didn't respond at first because I wanted to look into it. When I went to respond, it was gone.
Thanks - I learnt a lot for this. One slight thing - if the cancellation was checked *after* progress is reported it would be a little more accurate. When you cancel at 50%, the code has actually completed 60% of the downloads, but the reporting callback hadn’t been called. I know it doesn’t matter for this example, but there could be instances where that information is useful.
Tim, it was your approach to teaching, your competency and your conciseness that made it a pleasure to subscribe to your Annual Pass. I look forward to learning more. Well done!
Hey, i love you videos very well explained. To make them even better you could seperate them by topics and add a playlist like: 1. Progress Reports 2.cancelling tasks 3.more advanced async in playlist Advanced async. The reason is i'm only interested in cancelling tasks for today and i have no idea where to start in the video. 1 hour videos scare people :).
Thanks for the suggestion. The biggest thing is getting the time to do that. If you come up with some good time codes, I'll add them to the description.
I very much appreciate your teaching skill. I might note that with the examples of IProgress that I've seen to this point, there is usually a null check involved in calling Report(). I'm not entirely sure of the reason at this point, but thought this might be useful.
I concur with "InDeep Software". I've been programming for 40 years and this is the most effective approach I've come across. I've been using PluralSight lately, which can be good. This is better ... Thank you!
I hit like button before I watch the video case I'm sure it will be useful and enjoining. Beside that, my native language is Arabic and I understand the clear and simple English you use in videos. Thanks Tim.
Awesome videos man! Keep it up! I've been been programming for years but certain concepts I tend to avoid, like asynchronous programming. I really like the way you break everything down into simple digestible steps and don't spend hours digging into historical context that is irrelevant for today, you get right to the nuts and bolts. I have already sub'd but I'd do it again if I could! Thanks for spreading the knowledge!
Hi Tim, great content. Would love to see more. I have a question about the methods where you use the Parallel.ForEach. I noticed that it stores the output in a List versus a ConcurrentBag. I thought List where not async safe. Can you explain?
Hey, great video, as always! You're a great teacher. I ran into a problem when I re-ran the Async method after cancelling once. I think I found this issue; the CancellationTokenSource property IsCancellationRequested is set to true, and is not reset anymore. This causes the further iterations to cancel automatically. I solved it by adding a finally block, disposing of the cts and setting it to a new instance. Since IsCancellationRequested a read-only, I could not reset it. I also added the cancel token to the AsyncV2, but it crashed form an AggregateException; adding an additional catch block solved it.
Dear tim, Again one million thx. as always, it's just very helpfull and explained in a so simple way that even at nearly at 50 years (in my cas) we just feel again as at university.
This is by far the best video on async/ await in c# and the content beats any of the paid video sources out there. I have a question is there a way to pause-resume operation instead of just canceling it?
Hi Tim! Thanks for the 2 detailed vids about Async. I am kinda left stuck on 1 specific thing: according o the Microsoft Docs regarding asynchronous programming, you need to check if it is I/O work or CPU bound work you want to do. MS says to not use Task.Run nor parallel regarding I/O bound work. They say Async/Await is enough. That being said, what is "Downloadstring" in this example? Is this I/O work or CPU work? I thought it to be I/O work so when I saw Task.Run and parallel I got confused.
This is a really excellent video. I would love to see something similar for VSTO with C# for Excel. I'm finding it really hard to get good and easy to follow best practice info on how to show long running tasks in forms in with a responsive progressbar. But a series on building Excel add-ins in a best practice manner with VSTO in general would also be wonderful. Thanks for the awesome content!
You can also build an average metric and predict your progress. Say in this example average the time a few times running the method for a given byte size and you can remap with the expected value.
Hmm, for reports back from the task I have used Dispatcher.Invoke()/Dispatcher.BeginInvoke() in the past. What are the differences to using IProgress.Report(), what is better practice and why? Again, very informative Videos. As a Beginner-Immediate Programmer I find it difficult to find tutorials which do not focus either on very specialized stuff or on the very basics. Your content fits my leaning progress perfectly!
Your way is using threading directly. Async isn't necessarily multi-threading (but can be - you just don't know or care). I believe BeginInvoke/Invoke will also crash your app on unhandled exceptions where Async will not.
Thanks for showing the gradual improvements you made from basics to advanced! Now I am beginning to understand how async/await is used. I have 2 questions 1. How to include threads in a flow chart. If I had to draw flow chart for this program how would I include threads? 2. Where is the progress.ProgressChanged (from MainWindow.executeAsync_Click()) invoked? I didn't see ProgressChanged ?.Invoke(this, ProgressReportModel); anywhere in the code!
Thanks Tim for this great video tutorial. This was just helping to point myself into the right direction implementing some code for a massive parallel backup job.
Very insightful, even in 2021! I got the basics down but I am still wondering why the ProgressChanged += ReportProgress doesn't print out 10 separate times. First 1, then 2, then 3, then 4 and so. I'd expect the Text window to be filled with 55 download messages... *edit:* I looked back and saw each time the PrintResults is called the entire text box is reset. A bit of a nasty solution if you ask me, but to each their own. This explains my unexpected result.
You have a race condition in RunDownloadParallelAsyncV2. As all files are being downloaded at the same time it is possible for the Tasks to finish at the same time and accessing output.Add at the exact same time. Best solution is probably to use a ConcurrentQueue and Dequeue it in in a loop in the log printing part of code. Other way is to introduce a lock on the list.
Hey Tim can you add the subject start times to the description? Example: Review of previous video 1:15 Section on reporting: 14:56 Section blah blah blah... 45:67 Recap 70:34 Love the video but it would bring value to know precisely where the video speaks to feature X
I don't have the time to go through my videos and add timestamps, but if you provide timestamps, I will add them to the description. So far, Ralfs HBK has been doing that for a number of my videos, so a lot of my videos have timestamps now.
@@IAmTimCorey Hey Tim. I'm just trying to give something back to you and community :) I'm glad you find them good enough to add to your video descriptions :) Videos I'm following are form "Learning path" playlists in order.
This video and your Basic Async / Await video were very helpful, thank you. I would like to see a video on how and where exceptions are best handled. Thanks!
Thank you. All of your videos are wonderfull, so many knwoledge perfectly presented (Even with my low English I can understand everything). I am only sad that for financial reality of my country your courses are a bit too expensive :( . I hope that in future you will make another video with pracitical use of the async or talk more about what's inside of this, but I am not sure this will fit to your convention.
Great work Tim, love your videos. @49:30 - is the setting of the progress thread safe? I suppose that the body of the lambda is executed by the threads spawned by the ForEach( ... ), if so the progress must be itself thread safe, or am I missing something? Thanks for the great work!
@@IAmTimCorey 4 years later this is still a valid and very good explanation. Actually with these 2 videos I was able to really understand what is "under the hood" of the Backgroundworker. Would you nowadays recommend to use the BGW or use a selfmade async method with progress report and cancellation? (provided both functionalities are needed)?
Hello Tim, thanks for the awesome content, learned a lot from this video. However I did find a bug in your code, and that is, once you hit the Cancel button once to stop the downloading process, the subsequent DownloadAsync button no longer works properly. The problem is that you didn't reinitialize the cts variable, so the IsCancellationRequested remains true. I worked around this by reinialize cts every time DownloadAsync button is clicked. Not sure whether my idea is right, and whether this work around is the best practice, please inform me some more, thanks a lot!
Thanks Tim. I rewatch this video to refresh my knowledge. Can you do a video covering the use of TaskCompletionSource to wrap an old school EAP implementation into an awaitable task.
To be accurate, running tasks in a loop and doing Task.WhenAll is not really parallelism, but more like multi-threading. Parallel.ForEach will give you true parallelism, however, it blocks, albeit for a very short time. You can still use it within Task.Run and get the best of both worlds though. Also, the latter is more efficient when creating tasks when looping over a big number of items.
Parallel.ForEach is effectively the same as kicking off tasks and then waiting for them all to finish. It is slightly more efficient I believe, but it is close. The reason being is that Parallel.ForEach doesn't actually run things in parallel either. It "Executes a foreach operation in which iterations may run in parallel" (from Microsoft's documentation). It is essentially doing what I was doing. It creates tasks and then runs them all, which doesn't really run them all but uses threading to identify how many can run at the same time and then queues them up in as many parallel tracks as possible (just like my implementation does).
Hi Tim. Actually I am a bit surprised that you didn't include Multithreading vs Async. I confuse those topics a little. It would be nice to learn them from you. Thanks for awesome content!
So why is it that if I click on a disconnected network drive inside the Windows Explorer it still freezes the entire instance of the Explorer until the timeout is done? Why does Microsoft not do this process async for the Windows Explorer?
Can you make a video where you go into detail about Synchronization Context and when/when not to use .configureAwait and the optimization benefits of it.
I am a professional WPF C# developer & find your resources by far superior to Pluralsight content. Very talented teacher, thank you so much.
You are most welcome.
Either this [advanced] concept is really simple or was it just explained in such a way that it seems very easy to use..... I'm really glad I found these videos. This concept is a game changer, for sure. I wish I would've found these years ago!
Glad it was helpful!
Great demo!
NOTE: You'll want to create a new cancel token before calling the async because on the next try the token will still be canceled.
CancellationTokenSource cts = null; // At declaration (top of class)
...
// In the executeAsync_Click() method...
cts = new CancellationTokenSource();
var results = await DemoMethods.RunDownloadAsync(progress, cts.Token);
PrintResults(results);
...
// In the cancelOperation_Click() method...
if (cts != null)
cts.Cancel();
Thanks for sharing
Exactly what i was looking for, thanks!!
Was about to report the same thing, but found your comment 👍
Thank you Tim. You are one of the very few video creators with real passion for what you do and for teaching people. Your videos are done in perfect pace, you stop at important parts and explain them. Simply amazing!
I appreciate that!
Tim, if it weren't for you, I'd still be messing around with a console application that does nothing useful. Your videos are one of the greatest learning sources I've ever come across. You've taught me many essential things in C#. Great work.
Other resources are nothing compared to what you provide (even for free!)
I appreciate the kind words.
💯
Honestly the best, most concise summary of a topic I find myself struggling with constantly. Excellent resource for software professionals and amateurs alike. Well done!
Thanks!
This was a great video. Understandable and informative. Thanks a lot.
The hard thing is not how hard the problem is.
The real problem is to explain it simply and easily, no matter how difficult it is. It's more difficult to simplify and make it understandable.
This is what you doing your videos.
Thank you!
I was very confused between synchronous and asynchronous programming & how to use async/await keywords. This video cleared my all confusion. Thanks you so much.
Wonderful!
Finally a tutorial that doesn't assume the viewers are experts already, I am able to follow and understand completely! Awesome work Tim, thank you!
You are welcome.
I cannot understate how much I love when Tim glues together 3 or 4 words in each phrase.. Saves me so much time =)
Tim, You are a great teacher! You explain complicated stuff in a clear and comprehensible way. I lean a lot from all your videos. Thank you!
You're very welcome!
Man I can’t believe how much I learned from your videos. I’ve gotten back into C# development for my job which involves a lot of automation. My tools are internal to our team, just basically making tools to automate a lot of mundane tasks that eat up our time. Can’t thank you enough for your help, you most definitely earned my sub
You are most welcome. Thanks for watching.
You are the best teacher to teach C# programming tutorials. I really understand your concepts in-depth as you explain with keeping everything in mind. Not too vague, or not too complex. Just enough spices to make the recipe (knowledge) tasty to consume! Aromatic and delightful. Please keep up the hard work. I pray for your wellbeing and may you be blessed with more success. InshaAllah 🤲❤. Lots of love from me brother.
Thank you!
I was having an awful time trying to make a bunch of legacy code I can't really change to run faster. Found your first video on async/await and managed to shave off a ridiculous amount of time. You are a life saver, thank you so much for your help!
Excellent!
Been struggling with creating a ASYNC fileDownloaded, but succeeded using CLASSES without using any threads, it works but the code was like spagetti, overlaps and overloads etc. So decided to revisit the code from last year and try to enhance my knowledge and using threads and tasks.. it worked to a certain point using Delegates and SafeData methods and invokes etc.. but still was not 100% something to be proud about, until I ran across your videos TIM.. thank you for the examples and level of detail and the download site.. AMAZING work.. and very much appreciated.
Awesome! I'm glad it helped out.
Everytime my lead dev asks me to do smthing confusing im like... "If theres a TimCorey for it im good".
Today was cancelation tokens and logging.
Cheers for saving my bacon again dude.
Awesome! Thanks for sharing!
Hey Tim, great video. Correct me if I'm wrong, but I think calling Add method on List inside Parallel.ForEach can lead to thread related issues as List is not thread-safe (according to MS only public static members are thread-safe).
It's necessary to employ synchronization techniques or use a concurrent collection to avoid any problems.
Yep, that was a mistake on my part. Good catch.
@@IAmTimCorey Would you please make a video explaining this and link it here?
Great video again. It helped me clear in my mind the actual difference between Task.WhenAll and Parallel.ForEach. Hats off to you Tim. Thanks for breaking down tough things in easy to understand manner for us.
You are welcome.
Both videos on Async / Await are awesome, from scratch to the advance with a visual touch. Wow you just open up my understanding of this topic. Bless you Tim Corey.
Great!
Your videos are pure gold. Superb explanation, excellent didactics, and execution sequence. Thank you so much.
Thank you!
I'm watching the end of the progress bar part thinking "Wow, I can't wait to do this. I will have to re-watch this and follow along but I should be able to figure it out if I try."
Tim Corey: 24:48
Seriously, though. This is explained extremely well. Thank you!
You are welcome.
When I see Tim upload a C# video world gets beautiful for an hour :)
I'm glad. Hopefully there will be many beautiful hours to come.
Thanks for the video!
1) suspend exceptions by using try catch is questionable practice
2) i would not use throw an exception to cancel the operation
3) if you want to cancel the operation do it in the beginning of the loop is better practice in this case due to hevy lifting is in web call
You are welcome.
The way Tim taught us in the video is the canonical way and the .NET recommended way. (token.ThrowIfCancellationRequested). Surprised!
Tim, sir, you're keeping me employed. It's sometimes hard finding these types of content and (especially C#) you just provide when needed.
Awesome! I'm glad you are getting a real benefit out of the content.
Hey Tim, I just finished Advanced Async course and to be honest, I learned so many things even though I have been working on c# for the last 8+ years . Keep up the good work
I am glad it was so helpful.
Just a few comments: 1) the CancelationTokenSource cannot be "reset" and a new one must be created for each use. 2) Parallel.ForEach uses multiple threads for each "chunk" of work, whereas the Task.WaitAll() method doesn't use threads. 3) In the Parallel.ForEach case, you might be able to use a ContinueWith to add the common progress handling as each download finishes (I haven't tested this, and it probably isn't a recommended technique).
Another outstanding presentation. Thank you for the methodic progression as you introduce more complex topics. You really make C# simple. I appreciate the section on token cancellation source, the Parallel.foreach overview, and the use of async to keep the UI responsive. The Progress logic was also helpful and a little cleaner than my own.
I am glad it was helpful.
Thank you Sir.
I was remembering you for all value you have been giving.
And when I opened RUclips got your notification.
You are welcome. I'm glad I'm providing value.
Hey, did you delete your last comment about your comments being deleted? I saw it but didn't respond at first because I wanted to look into it. When I went to respond, it was gone.
By the way, email me about this please instead of replying. I have a hard time finding deep replies. Email is tim (at) iamtimcorey (dot) com
0:00 - Intro
0:55 - Demo application walk through
5:05 - Code behind demo application
12:00 - Implementing a progress report for tasks to be done
23:11 - Progress report recap
25:02 - Canceling tasks/methods: Cancellation tokens
33:58 - Canceling recap
35:34 - Parallel synchronous operation : Parallel.ForEach
41:38 - Parallel asynchronous operation
46:56 - Conclusions
50:26 - Summary
Thanks! I added it to the description.
Thank you very much again. Once again a great video Tim! You are a natural born teacher! Best regards from Germany and God bless you.
You are most welcome. Thanks for watching.
Thanks - I learnt a lot for this. One slight thing - if the cancellation was checked *after* progress is reported it would be a little more accurate. When you cancel at 50%, the code has actually completed 60% of the downloads, but the reporting callback hadn’t been called. I know it doesn’t matter for this example, but there could be instances where that information is useful.
True. Thanks for pointing it out.
Just awesome! I like your pace AND the way you highlight those small details which makes the difference in a real-world intuitive app! Thanks, Tim!
You are welcome.
Tim, it was your approach to teaching, your competency and your conciseness that made it a pleasure to subscribe to your Annual Pass. I look forward to learning more. Well done!
Thank you! I am glad you are finding my content so valuable.
1) 39:18 List.Add in Parallel.ForEach is not thread-safe
2) Parallel.ForEach is multi-threading, not "normal"
Yep, I should have used a ConcurrentBag instead.
Hey, i love you videos very well explained. To make them even better you could seperate them by topics and add a playlist like: 1. Progress Reports 2.cancelling tasks 3.more advanced async in playlist Advanced async. The reason is i'm only interested in cancelling tasks for today and i have no idea where to start in the video. 1 hour videos scare people :).
Thanks for the suggestion. The biggest thing is getting the time to do that. If you come up with some good time codes, I'll add them to the description.
Learned quite a few things from watching this video and its predecessor. Thanks, Tim!
You are welcome.
I very much appreciate your teaching skill. I might note that with the examples of IProgress that I've seen to this point, there is usually a null check involved in calling Report(). I'm not entirely sure of the reason at this point, but thought this might be useful.
The reason is in case the reference has been destroyed or was null to begin with.
You are the best as i always say, thank you very much Mr. Corey
Thank you!
I concur with "InDeep Software". I've been programming for 40 years and this is the most effective approach I've come across. I've been using PluralSight lately, which can be good. This is better ... Thank you!
I appreciate the kind words.
I hit like button before I watch the video case I'm sure it will be useful and enjoining. Beside that, my native language is Arabic and I understand the clear and simple English you use in videos. Thanks Tim.
You are most welcome. Thanks for watching.
Excellent demo of Async - Parallel -Progress ever been seen !!
I appreciate the kind words.
Awesome videos man! Keep it up! I've been been programming for years but certain concepts I tend to avoid, like asynchronous programming. I really like the way you break everything down into simple digestible steps and don't spend hours digging into historical context that is irrelevant for today, you get right to the nuts and bolts. I have already sub'd but I'd do it again if I could! Thanks for spreading the knowledge!
I'm glad you are enjoying them and getting value out of them.
Hi Tim, great content. Would love to see more. I have a question about the methods where you use the Parallel.ForEach. I noticed that it stores the output in a List versus a ConcurrentBag. I thought List where not async safe. Can you explain?
A boneheaded mistake. Yep, that's about it. I should have used a thread-safe set instead of List. Good catch.
This is so much better than the async/await course on pluralsight.
Thanks!
Hey, great video, as always! You're a great teacher.
I ran into a problem when I re-ran the Async method after cancelling once.
I think I found this issue; the CancellationTokenSource property IsCancellationRequested is set to true, and is not reset anymore. This causes the further iterations to cancel automatically.
I solved it by adding a finally block, disposing of the cts and setting it to a new instance. Since IsCancellationRequested a read-only, I could not reset it.
I also added the cancel token to the AsyncV2, but it crashed form an AggregateException; adding an additional catch block solved it.
I'm glad you figured it out.
@@IAmTimCorey I could figure it all out from what you taught in the tutorial; like an easter-egg challenge. Really fun, thanks!
Corey, maybe exploring ValueTask and it's use cases would be good continuation of these async series.
Thank you so much for this video Tim! Never thought anybody cud explain me async operations so easily!
Thanks for trusting Tim for your training.
Cleary and great explanation... both videos show me a big diff between normal method and with async await method. luv the way u explain it
Glad it was helpful!
Once again: perfection in explanation, presentation and execution. Thank you Tim :)
You are welcome.
Dear tim, Again one million thx. as always, it's just very helpfull and explained in a so simple way that even at nearly at 50 years (in my cas) we just feel again as at university.
You're very welcome!
Thanks A LOT man, you really did better than my whole university program
I’m glad it was helpful.
Sir you have made my life easier beyond any thank you
Your videos is really helping me preparing for my new C# job, since I come from Java world. Keep it up man :)
Glad I could help!
Tim all materials you've posted are awesome!
Good luck and affluent numbers of students to you!
Thank you.
prob the best programming video ive seen
Thanks for sharing that.
except 90% of async is the weird error/exception handling required
fantastic tutorial Tim. really loved the detail you covered in the video. Thanks🙏
Thank you for continuing your learning with Tim.
It completely opened my mind. Thanks Tim for your amazing explanation.
You are welcome.
This is by far the best video on async/ await in c# and the content beats any of the paid video sources out there.
I have a question is there a way to pause-resume operation instead of just canceling it?
You would need to build that into the called method. It isn't a standard feature.
Thank you for these videos.
I really appreciate that you point out what comes from the .NET framework or built into to C#.
You are welcome.
Thank you for your videos, I have learned a lot about advance async and await methods. God bless you Tim.
You are most welcome. Thanks for watching.
Hi Tim! Thanks for the 2 detailed vids about Async. I am kinda left stuck on 1 specific thing: according o the Microsoft Docs regarding asynchronous programming, you need to check if it is I/O work or CPU bound work you want to do. MS says to not use Task.Run nor parallel regarding I/O bound work. They say Async/Await is enough. That being said, what is "Downloadstring" in this example? Is this I/O work or CPU work? I thought it to be I/O work so when I saw Task.Run and parallel I got confused.
I liked the video and able to follow and try the concepts with an example on my laptop. The concept is clear. Thanks a lot Tim.
You are most welcome. Thanks for watching.
This is a really excellent video. I would love to see something similar for VSTO with C# for Excel. I'm finding it really hard to get good and easy to follow best practice info on how to show long running tasks in forms in with a responsive progressbar. But a series on building Excel add-ins in a best practice manner with VSTO in general would also be wonderful. Thanks for the awesome content!
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
You can also build an average metric and predict your progress. Say in this example average the time a few times running the method for a given byte size and you can remap with the expected value.
I’ve got a pretty large code base for Excel automation in C#, if you still need help. What are you trying to do?
This series is very helpful. Though I am familiar with async await in .net, I wasn't sure how to get better performance with it. Well done sir. 💯
Thank you!
Excellent demo and explanation. Much appreciated Tim.
Glad it was helpful!
At 19:00 min. Integers don’t get rounded to the nearest whole number. They just truncate. Always rounding down
Yep, I misspoke. Thanks for correcting it.
Hmm, for reports back from the task I have used Dispatcher.Invoke()/Dispatcher.BeginInvoke() in the past. What are the differences to using IProgress.Report(), what is better practice and why?
Again, very informative Videos. As a Beginner-Immediate Programmer I find it difficult to find tutorials which do not focus either on very specialized stuff or on the very basics. Your content fits my leaning progress perfectly!
Your way is using threading directly. Async isn't necessarily multi-threading (but can be - you just don't know or care). I believe BeginInvoke/Invoke will also crash your app on unhandled exceptions where Async will not.
Thanks for showing the gradual improvements you made from basics to advanced! Now I am beginning to understand how async/await is used. I have 2 questions
1. How to include threads in a flow chart. If I had to draw flow chart for this program how would I include threads?
2. Where is the progress.ProgressChanged (from MainWindow.executeAsync_Click()) invoked? I didn't see ProgressChanged ?.Invoke(this, ProgressReportModel); anywhere in the code!
Thanks Tim for this great video tutorial. This was just helping to point myself into the right direction implementing some code for a massive parallel backup job.
Excellent!
Thanks Tim for make this easy to understand. I am looking for multithreading from you.
Glad to help
Brilliant stuff mate. I was struggling with this for a while, cheers for clearing it up.
Glad it helped
Nice Article on Async. Thanks a lot for all your work! It's amazing!
You are welcome.
Another great, exhaustive but clear video. Thank you! You, Sir, have earned a subscribe :)
You are most welcome. Thanks for watching.
What do you recommend? using Tasks and Parallel.foreach or using the Thread library?. Why don't you use the thread library for this?
Very insightful, even in 2021! I got the basics down but I am still wondering why the ProgressChanged += ReportProgress doesn't print out 10 separate times. First 1, then 2, then 3, then 4 and so. I'd expect the Text window to be filled with 55 download messages...
*edit:* I looked back and saw each time the PrintResults is called the entire text box is reset. A bit of a nasty solution if you ask me, but to each their own. This explains my unexpected result.
You have a race condition in RunDownloadParallelAsyncV2.
As all files are being downloaded at the same time it is possible for the Tasks to finish at the same time and accessing output.Add at the exact same time.
Best solution is probably to use a ConcurrentQueue and Dequeue it in in a loop in the log printing part of code.
Other way is to introduce a lock on the list.
Yep, I should have used a better list.
Hey Tim can you add the subject start times to the description?
Example:
Review of previous video 1:15
Section on reporting: 14:56
Section blah blah blah... 45:67
Recap 70:34
Love the video but it would bring value to know precisely where the video speaks to feature X
I don't have the time to go through my videos and add timestamps, but if you provide timestamps, I will add them to the description. So far, Ralfs HBK has been doing that for a number of my videos, so a lot of my videos have timestamps now.
@@IAmTimCorey Hey Tim.
I'm just trying to give something back to you and community :)
I'm glad you find them good enough to add to your video descriptions :)
Videos I'm following are form "Learning path" playlists in order.
Wow, you are a great mentor. Thanks.
My pleasure!
This video and your Basic Async / Await video were very helpful, thank you. I would like to see a video on how and where exceptions are best handled. Thanks!
I will add it to the list. Thanks for the suggestion.
Thank you. All of your videos are wonderfull, so many knwoledge perfectly presented (Even with my low English I can understand everything). I am only sad that for financial reality of my country your courses are a bit too expensive :( .
I hope that in future you will make another video with pracitical use of the async or talk more about what's inside of this, but I am not sure this will fit to your convention.
Glad you like them! Noted, and added to the list.
Another excellent presentation! Thank you Tim!
Thanks for investing your time with Tim
Great work Tim, love your videos. @49:30 - is the setting of the progress thread safe? I suppose that the body of the lambda is executed by the threads spawned by the ForEach( ... ), if so the progress must be itself thread safe, or am I missing something? Thanks for the great work!
The List is not. I should have used a ConcurrentBag instead.
these tutorials have helped me to understand a lot.
Thanks Tim!
My pleasure!
Really neat! was going crazy trying to make the BackgroundWorker class run, and this is so much better, specially when explained like this. Thanks!
I am glad it was so helpful.
@@IAmTimCorey 4 years later this is still a valid and very good explanation. Actually with these 2 videos I was able to really understand what is "under the hood" of the Backgroundworker.
Would you nowadays recommend to use the BGW or use a selfmade async method with progress report and cancellation? (provided both functionalities are needed)?
Tim My man! Your videos are great! keep up with this amazing work! your explanations skills are priceless!!!
Glad you like them!
excellent tutorial - i like the way you built it up in increments
Thank you!
Amazing . Love you Tim . You are really making it simple
Thanks for trusting Tim and looking to him for assistance
Thank you Tim. Very helpful. Made a significant impact on an app I'm building.
Excellent!
Hello Tim, thanks for the awesome content, learned a lot from this video. However I did find a bug in your code, and that is, once you hit the Cancel button once to stop the downloading process, the subsequent DownloadAsync button no longer works properly. The problem is that you didn't reinitialize the cts variable, so the IsCancellationRequested remains true. I worked around this by reinialize cts every time DownloadAsync button is clicked. Not sure whether my idea is right, and whether this work around is the best practice, please inform me some more, thanks a lot!
Great work! Amazing Parallel steps up my journey!!!
Thanks!
Thanks Tim. I rewatch this video to refresh my knowledge. Can you do a video covering the use of TaskCompletionSource to wrap an old school EAP implementation into an awaitable task.
I appreciate the suggestion and added it to my list.
To be accurate, running tasks in a loop and doing Task.WhenAll is not really parallelism, but more like multi-threading. Parallel.ForEach will give you true parallelism, however, it blocks, albeit for a very short time. You can still use it within Task.Run and get the best of both worlds though. Also, the latter is more efficient when creating tasks when looping over a big number of items.
Parallel.ForEach is effectively the same as kicking off tasks and then waiting for them all to finish. It is slightly more efficient I believe, but it is close. The reason being is that Parallel.ForEach doesn't actually run things in parallel either. It "Executes a foreach operation in which iterations may run in parallel" (from Microsoft's documentation). It is essentially doing what I was doing. It creates tasks and then runs them all, which doesn't really run them all but uses threading to identify how many can run at the same time and then queues them up in as many parallel tracks as possible (just like my implementation does).
Hi Tim. Actually I am a bit surprised that you didn't include Multithreading vs Async. I confuse those topics a little. It would be nice to learn them from you. Thanks for awesome content!
Thanks for the suggestion, I added it to the list.
So why is it that if I click on a disconnected network drive inside the Windows Explorer it still freezes the entire instance of the Explorer until the timeout is done? Why does Microsoft not do this process async for the Windows Explorer?
There are a number of reasons. It could be that it is intentional since others rely on it.
Thanks Tim Corey... Its a great learning for me... Thanks once again..
You are welcome.
Really great explanation of a fairly complex topic.
Thank you!
really learned a lot from this async/await series!
Excellent!
Can you make a video where you go into detail about Synchronization Context and when/when not to use .configureAwait and the optimization benefits of it.
I will add it to the list. Thanks for the suggestion.
I wish I could watch all your videos parallel and learn from them asynchronously...
Yeah, that would be nice.
Thanks a lot for all your work! It's amazing!
You are welcome.