diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs index 389cdd31e81..0f282eb77c9 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs @@ -242,27 +242,6 @@ int Run (MonoDevelopOptions options) var desktopService = Runtime.GetService ().Result; desktopService.SetGlobalMenu (commandService, DefaultWorkbench.MainMenuPath, DefaultWorkbench.AppMenuPath); - // Run the main loop - Gtk.Application.Invoke ((s, e) => { - MainLoop (options, startupInfo).Ignore (); - }); - Gtk.Application.Run (); - - IdeApp.IsRunning = false; - - IdeApp.Customizer.OnIdeShutdown (); - - instanceConnection.Dispose (); - - lockupCheckRunning = false; - Runtime.Shutdown (); - - IdeApp.Customizer.OnCoreShutdown (); - - InstrumentationService.Stop (); - - MonoDevelop.Components.GtkWorkarounds.Terminate (); - return 0; } @@ -403,6 +382,46 @@ async Task MainLoop (MonoDevelopOptions options, StartupInfo startupInfo) return 0; } + int Run (MonoDevelopOptions options, bool controlMainLoop) + { + var ret = Run (options); + if (ret != 0) { + return ret; + } + + if (controlMainLoop) { + // Run the main loop + Gtk.Application.Invoke ((s, e) => { + MainLoop (options, startupInfo).Ignore (); + }); + Gtk.Application.Run (); + + Shutdown (); + return 0; + } else { + MainLoop (options, startupInfo).Ignore (); + return 0; + } + } + + internal void Shutdown () + { + IdeApp.IsRunning = false; + + IdeApp.Customizer.OnIdeShutdown (); + + instanceConnection.Dispose (); + + lockupCheckRunning = false; + Runtime.Shutdown (); + + IdeApp.Customizer.OnCoreShutdown (); + + InstrumentationService.Stop (); + + GtkWorkarounds.Terminate (); + } + void RegisterServices () { Runtime.RegisterServiceType (); @@ -722,6 +741,11 @@ static void HandleException (Exception ex, bool willShutdown) } public static int Main (string[] args, IdeCustomizer customizer = null) + { + return Main (args, true, customizer); + } + + public static int Main (string[] args, bool controlMainLoop, IdeCustomizer customizer) { IdeStartupTracker.StartupTracker.Start (); @@ -752,7 +776,7 @@ public static int Main (string[] args, IdeCustomizer customizer = null) IdeStartupTracker.StartupTracker.MarkSection ("mainInitialization"); var app = new IdeStartup (); - ret = app.Run (options); + ret = app.Run (options, controlMainLoop); } catch (Exception ex) { LoggingService.LogFatalError ( string.Format ( @@ -761,7 +785,9 @@ public static int Main (string[] args, IdeCustomizer customizer = null) BrandingService.ApplicationName ), ex); } finally { - Runtime.Shutdown (); + if (controlMainLoop) { + Runtime.Shutdown (); + } } LoggingService.Shutdown ();