Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. public void LaunchGUI()
  2. {
  3. if (_guiWindow == null)
  4. {
  5. var windowThread = new Thread(() =>
  6. {
  7. try
  8. {
  9. // Create our context, and install it:
  10. SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));
  11.  
  12. AppBootstrapper.Initialize();
  13. var app = new App();
  14. app.InitializeComponent();
  15.  
  16.  
  17. //guiWindow = app.MainWindow;
  18. //// When the window closes, shut down the dispatcher
  19. //guiWindow.Closed += (s, e) =>
  20. // Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
  21. //guiWindow.Closed += (s, e) =>
  22. // guiWindow = null;
  23. //guiWindow.WindowState = WindowState.Minimized;
  24. //guiWindow.Show();
  25. //guiWindow.WindowState = WindowState.Normal;
  26. //guiWindow.Activate();
  27. // Start the Dispatcher Processing
  28. Dispatcher.Run();
  29. }
  30. catch (Exception e)
  31. {
  32. LogMessage("error in gui thread: " + e);
  33. //guiWindow.Close();
  34. //guiWindow = null;
  35. }
  36.  
  37. });
  38. windowThread.SetApartmentState(ApartmentState.STA);
  39. windowThread.IsBackground = true;
  40. windowThread.Start();
  41. }
  42. else
  43. {
  44. _guiWindow.WindowState = WindowState.Minimized;
  45. _guiWindow.Show();
  46. _guiWindow.WindowState = WindowState.Normal;
  47. _guiWindow.Activate();
  48. }
  49. }
  50. }
  51.  
  52. public void ShowGui()
  53. {
  54. if (guiWindow == null)
  55. {
  56. var windowThread = new Thread(() =>
  57. {
  58. try
  59. {
  60. // Create our context, and install it:
  61. SynchronizationContext.SetSynchronizationContext(
  62. new DispatcherSynchronizationContext(
  63. Dispatcher.CurrentDispatcher));
  64.  
  65. guiWindow = new MainWindow();
  66. // When the window closes, shut down the dispatcher
  67. guiWindow.Closed += (s, e) =>
  68. Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
  69. guiWindow.Closed += (s, e) =>
  70. guiWindow = null;
  71. guiWindow.WindowState = WindowState.Minimized;
  72. guiWindow.Show();
  73. guiWindow.WindowState = WindowState.Normal;
  74. guiWindow.Activate();
  75.  
  76. // Start the Dispatcher Processing
  77. Dispatcher.Run();
  78. }
  79. catch (Exception)
  80. {
  81. try
  82. {
  83. guiWindow.Close();
  84. }
  85. catch (Exception)
  86. {
  87.  
  88. throw;
  89. }
  90. guiWindow = null;
  91. }
  92.  
  93. });
  94. windowThread.SetApartmentState(ApartmentState.STA);
  95. windowThread.IsBackground = true;
  96. windowThread.Start();
  97. }
  98. else
  99. {
  100. guiWindow.WindowState = WindowState.Minimized;
  101. guiWindow.Show();
  102. guiWindow.WindowState = WindowState.Normal;
  103. guiWindow.Activate();
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement