GithubHelp home page GithubHelp logo

synchronization-context's Introduction

SynchronizationContext in .NET

A recommendation when writing async code in .NET is to use ConfigureAwait(false) whenever possible. Whether or not ConfigureAwait(false) actually has an effect depends on what context the code runs in. In general, use ConfigureAwait(false) unless you know that you need to capture the current context. General-purpose library code typically do not need to return back to the original context, while UI applications typically needs to be in the correct context to make changes to UI elements. See here for more details.

Not all environments publish a custom context by default. There is a custom context if SynchronizationContext.Current is not null, or if TaskScheduler.Current is not the thread pool context. The table below shows whether or not the environments have a custom context by default. For those environments where both columns have a ✅, you might consider skipping ConfigureAwait(false). Note that even though a custom context is not set by default, it is still possible for library code to override this.

Environment SynchronizationContext.Current is null TaskScheduler.Current is Thread Pool
ASP.NET Core (.NET Core)
ASP.NET Core (.NET Framework)
ASP.NET Core gRPC Service
ASP.NET MVC
ASP.NET Web API
ASP.NET Web Forms
Azure Durable Functions v2 Orchestrators
Azure Functions v1
Azure Functions v2
Azure Functions v3
Blazor Server
Blazor WebAssembly
Console App (.NET Core)
Console App (.NET Framework)
MSTest (.NET Core)
MSTest (.NET Framework)
NUnit (.NET Core)
WCF Service
Windows Forms (.NET Core)
Windows Forms (.NET Framework)
WPF (.NET Core)
WPF (.NET Framework)
Xamarin Forms (Android)
xUnit (.NET Core)

synchronization-context's People

Contributors

dependabot[bot] avatar sveinungf avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.