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

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<T>(Func<T> action); public static void ApplyContext(SynchronizationContext context, Action action); public static T ApplyContext<T>(SynchronizationContext context, Func<T> action); } }