Menu

You're Probably Using async/await Wrong (And It's Costing You)
πŸ“°
0

You're Probably Using async/await Wrong (And It's Costing You)

DEV CommunityΒ·shayan holakoueeΒ·about 1 month ago
#f4aRHvzG
#dotnet#csharp#aspnet#async#fullscreen#await
Reading 0:00
15s threshold

Let me be direct: most .NET developers I've seen , including myself, early on β€” treat async/await like a magic sprinkle. Slap it on a method, everything becomes non-blocking, ship it. Done. Except it's not done. And the bugs that come from that mindset are the worst kind: the ones that only show up under load, in production, at 2am. This article isn't an intro. I'm assuming you know what Task is and that you've written at least one async method before. What I want to do is get into the stuff that actually matters when you're building something real. The Myth of "Just Add async" Here's a pattern I see constantly: public async Task < List < Order >> GetOrdersAsync () { var orders = _db . Orders . ToList (); // synchronous, blocking return orders ; } Enter fullscreen mode Exit fullscreen mode This method is async in name only. It doesn't await anything. The compiler will actually warn you about this β€” and then generate a state machine that wraps a synchronous operation for absolutely no benefit.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More