Making async code run faster in C#

71516
161
3080
15.06.2021
Nick Chapsas

Nick Chapsas

14173719
145000
293
29.11.2011
GB
Описание видео:

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

Кадры из видео
Making async code run faster in C#
Making async code run faster in C#
Making async code run faster in C#
Making async code run faster in C#
Тэги из видео
Комментарии пользователей:
Alex Scigalszky
2022-06-02 09:11:28

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.

Kokujou5
2022-05-27 12:02:33

so now it's not async anymore, it's async parallel ;)

Slip Och
2022-05-26 22:59:39

great video as always Nick.

Y_U_NO_DIE
2022-05-24 21:08:48

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)

Nathan Mayes
2022-04-17 21:32:18

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.

Das Fahrer
2022-04-05 21:26:52

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?

Sam
2022-04-05 17:21:47

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.

Madison Bradley
2022-04-02 19:59:54

Would it be possible to get your visual studio settings? Layout, color scheme, etc..

Earthling
2022-03-26 22:23:09

Now this is some fancy stuff, thanks Nick!

Huggykaze
2022-03-13 22:36:39

Why not handle exceptions inside the tasks?

Wojciech Wilimowski
2022-02-21 21:24:33

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

Kevin
2022-02-10 00:17:53

Great content. I had to double check my playback speed wasnt 1.25 :) I watched in 0.75

David Klempfner
2022-01-27 06:08:43

@ 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.

i. t.
2022-01-25 18:02:43

first like, then watch... 👍

Jared Sowers
2022-01-24 13:53:23

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();

await Task.WhenAll(t1,t2,t3);
}

async Task Child ()
{
Thread.Sleep(1000);
await Task.Delay(1000);
}

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);

await Task.WhenAll(t1,t2,t3);

This will then return in the expected 2 seconds...

Mabakay
2021-12-18 19:58:36

This aggregated exception is invalid. WhenAll returns immediately after first exception so allTasks.Exception will be non-deterministic.

emirpc
2021-10-27 14:16:24

You've got 69.100 subscribers man... soon 69.420

Keyboard G
2021-09-16 02:28:18

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.

Josh Olson
2021-08-14 01:16:59

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.

Что ищут прямо сейчас
渋川難波の雀力UP講座 Shivraj Singh Chauhan скучно в симс 4 SOUL SCREAM haridwar dharamshala price добряк Ravindra Kumar Raju брюки pubg mobile pc nasıl indirilir Dhanu Rashi Aaj Ka Dhanu Rashifal eminem shade45 birkan sokullu sevgilisi Suryagrahad Chandragrahad docker symfony 6 garry's การท่องเที่ยว nadira kadirova padakkam プレミア labour card renewal up free in csc
Похожие видео
19.06.2021
Is Parallel.For/ForEach in C# actually worth it? (and how to modernize it)

Is Parallel.For/ForEach in C# actually worth it? (and how to modernize it)

08.09.2020
8 await async mistakes that you SHOULD avoid in .NET

8 await async mistakes that you SHOULD avoid in .NET

31.10.2021
40% faster JSON serialization with Source Generators in .NET 6

40% faster JSON serialization with Source Generators in .NET 6

11.05.2021
Stop wasting server resources by properly using CancellationToken in .NET

Stop wasting server resources by properly using CancellationToken in .NET

05.06.2021
How to work with text in .NET like a pro with Humanizer

How to work with text in .NET like a pro with Humanizer

14.07.2021
What are ASYNC and AWAIT in C#? Asynchronous Programming Tutorial

What are ASYNC and AWAIT in C#? Asynchronous Programming Tutorial

12.04.2020
ASYNC AWAIT c# - EASY WAY TO UNDERSTAND ASYNC METHODS

ASYNC AWAIT c# - EASY WAY TO UNDERSTAND ASYNC METHODS

18.10.2021
How type deconstruction keeps your C# code clean

How type deconstruction keeps your C# code clean

09.08.2020
Should you stop returning

Should you stop returning "null"? | Functional C#

28.03.2021
When to use ValueTask instead of Task and save precious memory in C#

When to use ValueTask instead of Task and save precious memory in C#

19.09.2021
How to write clean validation clauses in .NET

How to write clean validation clauses in .NET

30.03.2022
Writing C# without allocating ANY memory

Writing C# without allocating ANY memory

04.08.2022
Stop using the HttpClient the wrong way in .NET

Stop using the HttpClient the wrong way in .NET

10.03.2022
ASP.NET Core - Fire and forget - Execute Asynchronous Code and Not Waiting for It - No Libraries

ASP.NET Core - Fire and forget - Execute Asynchronous Code and Not Waiting for It - No Libraries

09.07.2021
What is Span in C# and why you should be using it

What is Span in C# and why you should be using it

24.02.2021
9

9 "rules" for cleaner code | Object Calisthenics