Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ConfigureAwait in general-purpose library #20

Open
mjebrahimi opened this issue Feb 5, 2020 · 0 comments
Open

Use ConfigureAwait in general-purpose library #20

mjebrahimi opened this issue Feb 5, 2020 · 0 comments

Comments

@mjebrahimi
Copy link

If you’re writing general-purpose library code, use ConfigureAwait(false).
For more information you can read Stephen Cleary's article, ConfigureAwait FAQ

If you think ConfigureAwait(false) is no longer necessary in .NET Core or ASP.NET Core.
It's wrong.

ASP.NET Core has not own SynchronizationContext. That means that code running in an ASP.NET Core app by default won’t see a custom SynchronizationContext, which lessens the need for ConfigureAwait(false) running in such an environment.

But it doesn’t mean, however, that there will never be a custom SynchronizationContext or TaskScheduler present. If some user code (or other library code your app is using) sets a custom context and calls your code, or invokes your code in a Task scheduled to a custom TaskScheduler, then even in ASP.NET Core your awaits may see a non-default context or scheduler that would lead you to want to use ConfigureAwait(false).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant