public static MessagePumpStrategy FromCurrentSynchronizationContext()
        {
            var context = SynchronizationContext.Current;

            if (context is SingleThreadedTestSynchronizationContext)
            {
                return(SingleThreadedTestMessagePumpStrategy.Instance);
            }

            return(WindowsFormsMessagePumpStrategy.GetIfApplicable()
                   ?? WpfMessagePumpStrategy.GetIfApplicable()
                   ?? NoMessagePumpStrategy.Instance);
        }
            public static MessagePumpStrategy GetIfApplicable()
            {
                if (!IsApplicable(SynchronizationContext.Current))
                {
                    return(null);
                }

                if (_instance is null)
                {
                    var applicationType = SynchronizationContext.Current.GetType().Assembly.GetType("System.Windows.Forms.Application", throwOnError: true);

                    var applicationRun = (Action)applicationType
                                         .GetMethod("Run", BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly, null, Type.EmptyTypes, null)
                                         .CreateDelegate(typeof(Action));

                    var applicationExit = (Action)applicationType
                                          .GetMethod("Exit", BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly, null, Type.EmptyTypes, null)
                                          .CreateDelegate(typeof(Action));

                    _instance = new WindowsFormsMessagePumpStrategy(applicationRun, applicationExit);
                }

                return(_instance);
            }