<PackageReference Include="System.Reactive" Version="6.0.0" />

SynchronizationContextExtensions

using System.Runtime.CompilerServices; using System.Threading; namespace System.Reactive.Concurrency { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] internal static class SynchronizationContextExtensions { public static void PostWithStartComplete<[System.Runtime.CompilerServices.Nullable(2)] T>(this SynchronizationContext context, Action<T> action, T state) { context.OperationStarted(); context.Post(delegate(object o) { try { action((T)o); } finally { context.OperationCompleted(); } }, state); } public static void PostWithStartComplete(this SynchronizationContext context, Action action) { context.OperationStarted(); context.Post(delegate { try { action(); } finally { context.OperationCompleted(); } }, null); } } }