Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is CA2007 relevant to a .NET Core application?

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?

like image 807
Tom Wright Avatar asked Nov 30 '18 01:11

Tom Wright


People also ask

Is ConfigureAwait necessary in .NET core?

It's needed when running on . NET Core for exactly the same reasons it's needed when running on . NET Framework.

Is ConfigureAwait still necessary?

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).

What is ConfigureAwait () used for?

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 .


1 Answers

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

like image 194
Sabilace Avatar answered Sep 20 '22 18:09

Sabilace