DEV Community

loading...

Discussion on: How C# asynchronous programming is different than what you think

Collapse
turnerj profile image
James Turner

I do like the way async/await works in C#, it only felt like a burden when my entire app was synchronous but once I started moving to async, it became easier and easier.

With some of the examples in your post though, I would be careful with how they use async. Things like async void, returning a task without awaiting, and calling task.Result can have different issues in different circumstances.

Here is a good guide of when and how to use async/await which covers how/why some of those aspects can be bad: github.com/davidfowl/AspNetCoreDia...

That guide might be aimed at ASP.Net Core however many (maybe all) aspects are still relevant outside of it.

Collapse
yaser profile image
Yaser Al-Najjar Author • Edited

Thanks for letting me know... for the sake of completing the article I didn't look carefully into the codes, I just copied and pasted couple of examples from various places and mentioned their sources; I will update the examples soon.

Collapse
turnerj profile image
James Turner • Edited

No problem 🙂

Some of these things about async/await aren't all that obvious and different understanding of how to use it likely changed over time. The people that probably wrote the example code probably had it based on old information.

One of the things that gets me still with the async/await pattern is whether I need to call ConfigureAwait(false) or not - there seems to be a lot of different opinions about it online from a variety of people smarter than me.

Thread Thread
yaser profile image
Yaser Al-Najjar Author

Yeah, I still remember the first days I was cluelessly reading different articles about async C# and mixing new code with old one :D

C# is moving a bit fast that I feel sometimes it's burdensome to catch up with their latest updates.

Thread Thread
turnerj profile image
James Turner

C# is moving a bit fast that I feel sometimes it's burdensome to catch up with their latest updates.

I feel the same way about JavaScript!

As much as some of the new features that are being released (in JS, C#, CSS etc) are helpful and solves certain problems, there are some cases where I just look at it and wonder how we got here as it doesn't look easier/better than what existed.

Thread Thread
yaser profile image
Yaser Al-Najjar Author

JavaScript is a whole different story 😆

They just add all sort of keywords and features into the language just to feel "Oh, JavaScript can do that too" 😑

Thread Thread
asparallel profile image
AsParallel

Ecmascript is actually the result of a large, multi-national consortium of some of the best minds in the industry. They put a lot of effort into producing the spec and provide reasons for inclusion or exclusion of features in gory detail as part of that process.

It's not the javascript of 20 years ago.

Forem Open with the Forem app