Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Fody/ConfigureAwait
Configure async code's ConfigureAwait at a global level
https://github.com/Fody/ConfigureAwait
Last synced: 11 days ago
JSON representation
Configure async code's ConfigureAwait at a global level
- Host: GitHub
- URL: https://github.com/Fody/ConfigureAwait
- Owner: Fody
- License: mit
- Created: 2015-02-14T11:42:11.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-12T11:42:45.000Z (7 months ago)
- Last Synced: 2024-04-14T00:27:14.395Z (7 months ago)
- Language: C#
- Homepage:
- Size: 1.17 MB
- Stars: 439
- Watchers: 6
- Forks: 35
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
- awesome - Fody/ConfigureAwait - Configure async code's ConfigureAwait at a global level (C\#)
README
# ConfigureAwait.Fody
[![Chat on Gitter](https://img.shields.io/gitter/room/fody/fody.svg)](https://gitter.im/Fody/Fody)
[![NuGet Status](https://badge.fury.io/nu/configureawait.fody.svg)](https://www.nuget.org/packages/ConfigureAwait.Fody/)Configure async code's [`ConfigureAwait`](https://msdn.microsoft.com/en-us/library/system.threading.tasks.task.configureawait) at a global level.
**See [Milestones](../../milestones?state=closed) for release notes.**
### This is an add-in for [Fody](https://github.com/Fody/Home/)
**It is expected that all developers using Fody [become a Patron on OpenCollective](https://opencollective.com/fody/contribute/patron-3059). [See Licensing/Patron FAQ](https://github.com/Fody/Home/blob/master/pages/licensing-patron-faq.md) for more information.**
## Usage
See also [Fody usage](https://github.com/Fody/Home/blob/master/pages/usage.md).
### NuGet package
Install the [ConfigureAwait.Fody NuGet package](https://nuget.org/packages/ConfigureAwait.Fody/) and update the [Fody NuGet package](https://nuget.org/packages/Fody/):
```
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.
### How to use it
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 levelExplicitly configured awaiters will not be overwritten by the weaver, allowing exceptions to the Assembly / Class / Method level setting.
### Add to FodyWeavers.xml
Add `` to [FodyWeavers.xml](https://github.com/Fody/Home/blob/master/pages/usage.md#add-fodyweaversxml)
```xml
```
It is also possible set the default ContinueOnCapturedContext in the xml config:
```xml
```
## Example
### Before code
```csharp
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);
}
}
```### What gets compiled
```csharp
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);
}
}
```## Icon
Created by Dmitry Baranovskiy from [The Noun Project](https://thenounproject.com).