Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void LaunchGUI()
- {
- if (_guiWindow == null)
- {
- var windowThread = new Thread(() =>
- {
- try
- {
- // Create our context, and install it:
- SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));
- AppBootstrapper.Initialize();
- var app = new App();
- app.InitializeComponent();
- //guiWindow = app.MainWindow;
- //// When the window closes, shut down the dispatcher
- //guiWindow.Closed += (s, e) =>
- // Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
- //guiWindow.Closed += (s, e) =>
- // guiWindow = null;
- //guiWindow.WindowState = WindowState.Minimized;
- //guiWindow.Show();
- //guiWindow.WindowState = WindowState.Normal;
- //guiWindow.Activate();
- // Start the Dispatcher Processing
- Dispatcher.Run();
- }
- catch (Exception e)
- {
- LogMessage("error in gui thread: " + e);
- //guiWindow.Close();
- //guiWindow = null;
- }
- });
- windowThread.SetApartmentState(ApartmentState.STA);
- windowThread.IsBackground = true;
- windowThread.Start();
- }
- else
- {
- _guiWindow.WindowState = WindowState.Minimized;
- _guiWindow.Show();
- _guiWindow.WindowState = WindowState.Normal;
- _guiWindow.Activate();
- }
- }
- }
- public void ShowGui()
- {
- if (guiWindow == null)
- {
- var windowThread = new Thread(() =>
- {
- try
- {
- // Create our context, and install it:
- SynchronizationContext.SetSynchronizationContext(
- new DispatcherSynchronizationContext(
- Dispatcher.CurrentDispatcher));
- guiWindow = new MainWindow();
- // When the window closes, shut down the dispatcher
- guiWindow.Closed += (s, e) =>
- Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
- guiWindow.Closed += (s, e) =>
- guiWindow = null;
- guiWindow.WindowState = WindowState.Minimized;
- guiWindow.Show();
- guiWindow.WindowState = WindowState.Normal;
- guiWindow.Activate();
- // Start the Dispatcher Processing
- Dispatcher.Run();
- }
- catch (Exception)
- {
- try
- {
- guiWindow.Close();
- }
- catch (Exception)
- {
- throw;
- }
- guiWindow = null;
- }
- });
- windowThread.SetApartmentState(ApartmentState.STA);
- windowThread.IsBackground = true;
- windowThread.Start();
- }
- else
- {
- guiWindow.WindowState = WindowState.Minimized;
- guiWindow.Show();
- guiWindow.WindowState = WindowState.Normal;
- guiWindow.Activate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement