When I run FxCop on my project, I get a large number of warnings with the ID of CA2007. This ID is missing from the docs (it just skips from CA2006 to CA2100), but the message I get is:
Do not directly await a Task without calling ConfigureAwait
I was under the impression that .NET Core didn't use synchronisation contexts and that this meant I didn't need to use .ConfigureAwait(bool)
. When I try and Google it though, I can now only find mentions of ASP.NET Core (e.g. this blog post).
Given that I can't find anything authoritative, I'm beginning to wonder whether I've mistaken an ASP.NET Core change for one that applies more generally to all of .NET Core.
Can anyone give me a definitive answer?
Should I need to go through my app and apply a liberal sprinkling of ConfigureAwait
? Or should I just disable CA2007 in my FxCop ruleset?
It's needed when running on . NET Core for exactly the same reasons it's needed when running on . NET Framework.
There are very few use cases for the use of ConfigureAwait(true), it does nothing meaningful actually. In 99% of the cases, you should use ConfigureAwait(false). In . NET Framework by default the Task execution will continue on the captured context, this is ConfigureAwait(true).
In the code that relies on the asynchronous programming model ( async / await keywords), ConfigureAwait() calls are often used to manage the synchronization context. The way ConfigureAwait() calls work and their usage scenarios are explained in detail in this Microsoft .
Yes in some situations. If your code is ever used as a library or someone introduces a SynchronizationContext. refer to this article. https://devblogs.microsoft.com/dotnet/configureawait-faq/#ive-heard-configureawaitfalse-is-no-longer-necessary-in-net-core-true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With