Become a Patreon and get source code access: 🤍🤍patreon.com/nickchapsas Check out my courses: 🤍nickchapsas.com Hello everybody I'm Nick and in this video I am going to show you how you can detect use-cases where you can make async code perform faster. The usecase is relatively nieche but common enought that you might be able to use it in one way or another. Don't forget to comment, like and subscribe :) Social Media: Follow me on GitHub: 🤍bit.ly/ChapsasGitHub Follow me on Twitter: 🤍bit.ly/ChapsasTwitter Connect on LinkedIn: 🤍bit.ly/ChapsasLinkedIn Keep coding merch: 🤍keepcoding.shop #csharp #dotnet #async
Excelent work! I love this videos. One question: What is the best approach to fetch all available data? Is one of them fail, don't matter give me the others two.
so now it's not async anymore, it's async parallel ;)
great video as always Nick.
You know people calling themselves developers are getting dangerously dumb when you have to play Cpt. Obvious with a straight face (sad native code noises)
You're a hero. I just started using c# to make a web app using blazor, and have been using the html5 canvas which has all of its functions asynchronous.
I was thinking having await on every single function call is gonna mean it's basically just running sychronously, but surely they could be run in parallel. This is literally exactly what I was looking for.
Interesting, but how do you do the TaskExt.WhenAll when the params are all different types? Also, what if you need to return an ObservableCollection instead of an IEnumerable?
Thanks for your videos man we always learn a lot from you. I've tested WhenAll on a large list, it does not execute them together or faster at all though. It just lets you know when all the tasks have been complete.
The only method that made the task run in parallel is the good old Parallel.ForEach method.
Would it be possible to get your visual studio settings? Layout, color scheme, etc..
Now this is some fancy stuff, thanks Nick!
Why not handle exceptions inside the tasks?
I didn't actually realize you could get the AggregateException out of the WhenAll task, I always used to do tasks.Select(t => t.Exception). Makes so much more sense in hindsight
Great content. I had to double check my playback speed wasnt 1.25 :) I watched in 0.75
@ gW19LaAYczI&t=3m17s 3:17 you mention those tasks won't start at that point. I thought they would start but all almost at the same time? The task object returned would just represent the work being done. await doesn't start them but just doesn't let execution continue past that line until the task being awaited is done.
first like, then watch... 👍
One thing to note is that the child methods do, in fact, run immediately and only return to the main method once something is actually awaited in the child method.
Try playing around with something like this:
async Task main()
var t1 = Child();
var t2 = Child();
var t3 = Child();
async Task Child ()
This will take 4 seconds to complete... I have seen this many times when people try to use async to achieve parallel code. If you truly want the execution to be parallel then you cannot use this method, you must do something similar to:
var t1 = Task.Run(Child);
var t2 = Task.Run(Child);
var t3 = Task.Run(Child);
This will then return in the expected 2 seconds...
This aggregated exception is invalid. WhenAll returns immediately after first exception so allTasks.Exception will be non-deterministic.
You've got 69.100 subscribers man... soon 69.420
If the a chance your task function is computed, still use await, change it to return a ValueTask. This keeps .result out of your code base. No state machine is already completed.
Correction: those tasks will (probably) start running the moment you call them, Task.WhenAll doesn't start them. It just waits till they're all complete before that stack continues.