dennisdoomen / CSharpGuidelines

A set of coding guidelines for C# 9.0, design principles and layout rules for improving the overall quality of your code development.
https://www.csharpcodingguidelines.com
Other
746 stars 271 forks source link

AV1820 : Async usage #163

Closed Kryptos-FR closed 5 years ago

Kryptos-FR commented 6 years ago

It just adds the necessary logic to allow releasing the current thread, and marshal the result back on that same thread [...]

This depends on the current SynchronizationContext and/or TaskScheduler (default one for GUI thread resumes on same context) and whether ConfigureAwait() was specified or not.

In other words, use async only for I/O bound operations.

It seems too restricitve. There are other scenarios where async/await might make sense. For example to make a UI responsive. Additionally, much like the IDisposable patter, async/await is a kind of "contaminating" pattern and when you start using it you often have to go all the way and make other methods async as well, avoiding the smelly async void case.

dennisdoomen commented 6 years ago

This depends on the current SynchronizationContext and/or TaskScheduler (default one for GUI thread resumes on same context) and whether ConfigureAwait() was specified or not.

You're right. We need to rephrase that.

For example to make a UI responsive.

If it involves an I/O intensive operation, then yes. But if it's CPU bound, you'll need to queue a task using the Task.Run, right?