Configure async code's ConfigureAwait
at a global level.
This is an add-in for Fody
It is expected that all developers using Fody become a Patron on OpenCollective. See Licensing/Patron FAQ for more information.
See also Fody usage.
Install the ConfigureAwait.Fody NuGet package and update the Fody NuGet package:
PM> Install-Package Fody
PM> Install-Package ConfigureAwait.Fody
The Install-Package Fody
is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.
By default, ConfigureAwait.Fody
doesn't change any code. Set a configure await value at the assembly, class, or method level.
[assembly: Fody.ConfigureAwait(false)]
- Assembly level[Fody.ConfigureAwait(false)]
- Class or method level
Explicitly configured awaiters will not be overwritten by the weaver, allowing exceptions to the Assembly / Class / Method level setting.
Add <ConfigureAwait/>
to FodyWeavers.xml
<Weavers>
<ConfigureAwait/>
</Weavers>
It is also possible set the default ContinueOnCapturedContext in the xml config:
<Weavers>
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>
using Fody;
[ConfigureAwait(false)]
public class MyAsyncLibrary
{
public async Task MyMethodAsync()
{
await Task.Delay(10);
await Task.Delay(20).ConfigureAwait(true);
}
public async Task AnotherMethodAsync()
{
await Task.Delay(30);
}
}
public class MyAsyncLibrary
{
public async Task MyMethodAsync()
{
await Task.Delay(10).ConfigureAwait(false);
await Task.Delay(20).ConfigureAwait(true);
}
public async Task AnotherMethodAsync()
{
await Task.Delay(30).ConfigureAwait(false);
}
}
Created by Dmitry Baranovskiy from The Noun Project.