Skip to content
0:00 / 0:00

#asyncawait#task#.net

Is awaiting a Task instead of returning it directly in C# actually slower?

Nick Chapsas

429K subscribers • 62 videos on Hallway

YouTube
  • Recommended by 1 person: 1 on Stack Overflow and its sister sites.
  • Presented by Nick Chapsas
  • An opinion. It argues one side of a question engineers disagree on.

Intermediate. Assumes working knowledge.

71K views5 years ago1 recommendation

Programming languagesSystems programmingC# and .NETPerformance and optimizationConcurrency and parallelism

Nick Chapsas analyzes the performance differences and trade-offs between awaiting a Task and returning it directly in C#.

Become a Patreon and get source code access: patreon.com/nickchapsas Check out my courses: dometrain.com Hello everybody I'm Nick and in this video I wanna talk about one of the things I see all the time regarding performance and awaiy async and that's whether you should await a task or when possible returning it directly. There are many opinions on the matter and here is mine. 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 #dotnet #csharp #asyncawait

Why it's here

1 person recommends this

What people say. Recommended for understanding the performance and architectural implications of returning a Task directly versus using async/await in C#.

Moments people linked to

julealgonon Stack Overflow • Recommends

On “Split async method into two for code analysis?”

Am I correct, when I split this code in the following way? No. The correct way to split them would be like this: public Task DeleteColorSchemeAsync(ColorScheme colorScheme) { if (colorScheme == null) throw new ArgumentNullException(nameof(colorScheme)); if (colorScheme.IsDefault) throw new SettingIsDefaultException(); return DeleteColorSchemeInternalAsync(colorScheme); } private async Task DeleteColorSchemeInternalAsync(ColorScheme colorScheme) { _dbContext.ColorSchemes.Remove(colorScheme); await _dbContext.SaveChangesAsync(); } (note that the entry method is not async in this case). Or like this, using the newer local functions: public Task DeleteColorSchemeAsync(ColorS…
17View the answer