<PackageReference Include="Nito.AsyncEx.Tasks" Version="5.1.1" />

Nito.AsyncEx.SynchronizationContextSwitcher

public sealed class SynchronizationContextSwitcher : SingleDisposable<object>
Utility class for temporarily switching SynchronizationContext implementations.
namespace Nito.AsyncEx { public sealed class SynchronizationContextSwitcher { public static void NoContext(Action action); public static T NoContext<[System.Runtime.CompilerServices.Nullable(2)] T>(Func<T> action); public static void ApplyContext(SynchronizationContext context, Action action); public static T ApplyContext<[System.Runtime.CompilerServices.Nullable(2)] T>(SynchronizationContext context, Func<T> action); } }