Example #1
0
        private static UIThreadHelper Create()
        {
            UIThreadHelper       uiThreadHelper = new UIThreadHelper();
            ManualResetEventSlim initialized    = new ManualResetEventSlim();

            AppDomain.CurrentDomain.DomainUnload += uiThreadHelper.Destroy;
            AppDomain.CurrentDomain.ProcessExit  += uiThreadHelper.Destroy;

            // We want to maintain an application on a single STA thread
            // set Background so that it won't block process exit.
            Thread thread = new Thread(uiThreadHelper.RunMainThread)
            {
                Name = "WPF Dispatcher Thread"
            };

            thread.SetApartmentState(ApartmentState.STA);
            thread.IsBackground = true;
            thread.Start(initialized);

            initialized.Wait();
            uiThreadHelper.Invoke(() => {
                uiThreadHelper._thread        = thread;
                uiThreadHelper._syncContext   = SynchronizationContext.Current;
                uiThreadHelper._taskScheduler = new ControlledTaskScheduler(uiThreadHelper._syncContext);
            });
            return(uiThreadHelper);
        }
Example #2
0
 public BlockingLoopSynchronizationContext(UIThreadHelper threadHelper, SynchronizationContext innerSynchronizationContext)
 {
     _threadHelper = threadHelper;
     _innerSynchronizationContext = innerSynchronizationContext;
 }
Example #3
0
 public BlockingLoopSynchronizationContext(UIThreadHelper threadHelper)
 {
     _threadHelper = threadHelper;
 }