private static void RunInWpfWindow(Action <DispatchWpfObject2> action)
        {
            DispatchWpfObject2 window = null;

            ManualResetEventSlim ready = new ManualResetEventSlim(false);

            Thread windowThread = new Thread(
                () =>
            {
                window = new DispatchWpfObject2(ready);
                window.Show();
                ready.Set();
                Dispatcher.Run();
            });

            windowThread.SetApartmentState(ApartmentState.STA);
            windowThread.Start();

            ready.Wait();
            ready.Reset();

            action(window);

            ready.Wait();

            window.Dispatcher.InvokeShutdown();

            windowThread.Join();
        }
        private static void RunInWpfWindow(Action<DispatchWpfObject2> action)
        {
            DispatchWpfObject2 window = null;

            ManualResetEventSlim ready = new ManualResetEventSlim(false);

            Thread windowThread = new Thread(
                () =>
                {
                    window = new DispatchWpfObject2(ready);
                    window.Show();
                    ready.Set();
                    Dispatcher.Run();
                });

            windowThread.SetApartmentState(ApartmentState.STA);
            windowThread.Start();

            ready.Wait();
            ready.Reset();

            action(window);

            ready.Wait();

            window.Dispatcher.InvokeShutdown();

            windowThread.Join();
        }