Ejemplo n.º 1
0
        private void doTest(FrameEventHandler handler)
        {
            List <Exception> exceptions = new List <Exception>();
            var newWindowThread         = new Thread(() =>
            {
                // Create and show the Window
                _window = new Backend.MainWindow();

                _window.Closed += (s, e) =>
                                  Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);

                // Close the window after initialisation finished
                _window.webControl.LoadingFrameComplete += (s, e) =>
                {
                    try
                    {
                        handler.Invoke(s, e);
                    }
                    catch (Exception ex)
                    {
                        exceptions.Add(ex);
                        _window.Close();
                    }
                    _window.Close();
                };

                _window.Show();
                // Start the Dispatcher Processing
                Dispatcher.Run();
            });

            // Set the apartment state
            newWindowThread.SetApartmentState(ApartmentState.STA);
            // Make the thread a background thread
            newWindowThread.IsBackground = true;
            // Start the thread
            newWindowThread.Start();
            // Wait for thread to finish before completing test
            newWindowThread.Join();

            foreach (Exception ex in exceptions)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        private void doTest(FrameEventHandler handler)
        {
            List<Exception> exceptions = new List<Exception>();
            var newWindowThread = new Thread(() =>
            {
                // Create and show the Window
                _window = new Backend.MainWindow();

                _window.Closed += (s, e) =>
                    Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);

                // Close the window after initialisation finished
                _window.webControl.LoadingFrameComplete += (s, e) =>
                {
                    try
                    {
                        handler.Invoke(s, e);
                    }
                    catch (Exception ex)
                    {
                        exceptions.Add(ex);
                        _window.Close();
                    }
                    _window.Close();
                };

                _window.Show();
                // Start the Dispatcher Processing
                Dispatcher.Run();
            });

            // Set the apartment state
            newWindowThread.SetApartmentState(ApartmentState.STA);
            // Make the thread a background thread
            newWindowThread.IsBackground = true;
            // Start the thread
            newWindowThread.Start();
            // Wait for thread to finish before completing test
            newWindowThread.Join();

            foreach (Exception ex in exceptions)
                throw ex;
        }