public void RunWorkbench(WorkbenchSettings settings) { if (settings.RunOnNewThread) { Thread t = new Thread(RunWorkbenchInternal); t.SetApartmentState(ApartmentState.STA); t.Name = "SMFmain"; t.Start(settings); } else { RunWorkbenchInternal(settings); } }
/// <summary> /// Initializes the workbench (create the MainForm instance, construct menu from AddInTree etc.) /// and runs it using the supplied settings. /// This starts a new message loop for the workbench. By default the message loop /// is created on a new thread, but you can change the settings so that /// it is created on the thread calling RunWorkbench. /// In that case, RunWorkbench will block until FanHai GUI Framework is shut down! /// </summary> public void RunWorkbench(WorkbenchSettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } if (initStatus == SMFInitStatus.CoreInitialized) { initStatus = SMFInitStatus.Busy; helper.RunWorkbench(settings); if (settings.RunOnNewThread) { initStatus = SMFInitStatus.WorkbenchInitialized; } } else { throw new InvalidOperationException(); } }
void RunWorkbenchInternal(object settings) { WorkbenchSettings wbSettings = (WorkbenchSettings)settings; LoggingService.Info("Initializing workbench..."); WorkbenchSingleton.InitializeWorkbench(); LoggingService.Info("Starting workbench..."); Exception exception = null; // finally start the workbench. try { StartWorkbenchCommand wbc = new StartWorkbenchCommand(); callback.BeforeRunWorkbench(); if (Debugger.IsAttached) { wbc.Run(wbSettings.InitialFileList); } else { try { wbc.Run(wbSettings.InitialFileList); } catch (Exception ex) { exception = ex; } } } finally { LoggingService.Info("Unloading services..."); try { WorkbenchSingleton.OnWorkbenchUnloaded(); PropertyService.Save(); } catch (Exception ex) { LoggingService.Warn("Exception during unloading", ex); if (exception == null) { exception = ex; } } } LoggingService.Info("Finished running workbench."); callback.WorkbenchClosed(); if (exception != null) { const string errorText = "Unhandled exception terminated the workbench"; LoggingService.Fatal(exception); if (useSolarViewerFrameworkErrorHandler) { System.Windows.Forms.Application.Run(new ExceptionBox(exception, errorText, true)); } else { throw new RunWorkbenchException(errorText, exception); } } }