Exemple #1
0
        private static TestMainThreadService Create()
        {
            var mainThreadService = new TestMainThreadService();
            var initialized       = new ManualResetEventSlim();

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

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

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

            initialized.Wait();
            Dispatcher.FromThread(thread).Invoke(() => {
                mainThreadService.Thread      = thread;
                mainThreadService.SyncContext = SynchronizationContext.Current;
            });
            return(mainThreadService);
        }
Exemple #2
0
 internal TestMainThread(TestMainThreadService service, Action onDispose)
 {
     _service   = service;
     _onDispose = onDispose;
 }
Exemple #3
0
 public BlockingLoopSynchronizationContext(TestMainThreadService service, TestMainThread mainThread, SynchronizationContext innerSynchronizationContext)
 {
     _service    = service;
     _mainThread = mainThread;
     _innerSynchronizationContext = innerSynchronizationContext;
 }