GOPbIHbI4
Joined 9 years ago
Joined 9 years ago
For instance, if you have Enumerable.Any with a delegate that captures instance state, the runtime can stack-alloc it, and (if it's small) to inline it. This will achieve the performance of a manual code that obtains span out of a list and "inlines" the delegate logic into the loop itself!
I've seen cases when the application code was filled with it "to improve performance" or "to avoid deadlocks". And it was very hard to convince that this is not how ConfigureAwait should be used.
The same is true for libraries: if your library is specific to your application then you might decide (like the ASP.NET Core team) to stop using ConfigureAwait completely. It is needed for highly re-uses able libraries that can be used in different contexts, which is quite rare.
In this video I'm covering why we have ConfigureAwait in the first place and how to use it correctly.
P.S. There are lot of discussions how broken ConfigureAwait is and a lot of people propose the fixes - like having a library specific annotation to implicitly add ConfigureAwait(false) to every await, or not depending on the configuration. But those discussions are still opened on GitHub with no plans on fixing it.
P.P.S. Another way is to use runtime code generation like Fody, but most of the people are not going to use them.
This video shows how to debug async methods line-by-line to understand exactly how async/await works under the hood.
There are a few tricks you can during the build to add custom attributes, or you can use PolySharp.
This video shows some neat recent C# language features and how to use them with .NET Framework or .netstandard.