@@ -242,27 +242,6 @@ int Run (MonoDevelopOptions options)
242
242
var desktopService = Runtime . GetService < DesktopService > ( ) . Result ;
243
243
desktopService . SetGlobalMenu ( commandService , DefaultWorkbench . MainMenuPath , DefaultWorkbench . AppMenuPath ) ;
244
244
245
- // Run the main loop
246
- Gtk . Application . Invoke ( ( s , e ) => {
247
- MainLoop ( options , startupInfo ) . Ignore ( ) ;
248
- } ) ;
249
- Gtk . Application . Run ( ) ;
250
-
251
- IdeApp . IsRunning = false ;
252
-
253
- IdeApp . Customizer . OnIdeShutdown ( ) ;
254
-
255
- instanceConnection . Dispose ( ) ;
256
-
257
- lockupCheckRunning = false ;
258
- Runtime . Shutdown ( ) ;
259
-
260
- IdeApp . Customizer . OnCoreShutdown ( ) ;
261
-
262
- InstrumentationService . Stop ( ) ;
263
-
264
- MonoDevelop . Components . GtkWorkarounds . Terminate ( ) ;
265
-
266
245
return 0 ;
267
246
}
268
247
@@ -403,6 +382,46 @@ async Task<int> MainLoop (MonoDevelopOptions options, StartupInfo startupInfo)
403
382
return 0 ;
404
383
}
405
384
385
+ int Run ( MonoDevelopOptions options , bool controlMainLoop )
386
+ {
387
+ var ret = Run ( options ) ;
388
+ if ( ret != 0 ) {
389
+ return ret ;
390
+ }
391
+
392
+ if ( controlMainLoop ) {
393
+ // Run the main loop
394
+ Gtk . Application . Invoke ( ( s , e ) => {
395
+ MainLoop ( options , startupInfo ) . Ignore ( ) ;
396
+ } ) ;
397
+ Gtk . Application . Run ( ) ;
398
+
399
+ Shutdown ( ) ;
400
+ return 0 ;
401
+ } else {
402
+ MainLoop ( options , startupInfo ) . Ignore ( ) ;
403
+ return 0 ;
404
+ }
405
+ }
406
+
407
+ internal void Shutdown ( )
408
+ {
409
+ IdeApp . IsRunning = false ;
410
+
411
+ IdeApp . Customizer . OnIdeShutdown ( ) ;
412
+
413
+ instanceConnection . Dispose ( ) ;
414
+
415
+ lockupCheckRunning = false ;
416
+ Runtime . Shutdown ( ) ;
417
+
418
+ IdeApp . Customizer . OnCoreShutdown ( ) ;
419
+
420
+ InstrumentationService . Stop ( ) ;
421
+
422
+ GtkWorkarounds . Terminate ( ) ;
423
+ }
424
+
406
425
void RegisterServices ( )
407
426
{
408
427
Runtime . RegisterServiceType < ProgressMonitorManager , IdeProgressMonitorManager > ( ) ;
@@ -722,6 +741,11 @@ static void HandleException (Exception ex, bool willShutdown)
722
741
}
723
742
724
743
public static int Main ( string [ ] args , IdeCustomizer customizer = null )
744
+ {
745
+ return Main ( args , true , customizer ) ;
746
+ }
747
+
748
+ public static int Main ( string [ ] args , bool controlMainLoop , IdeCustomizer customizer )
725
749
{
726
750
727
751
IdeStartupTracker . StartupTracker . Start ( ) ;
@@ -752,7 +776,7 @@ public static int Main (string[] args, IdeCustomizer customizer = null)
752
776
IdeStartupTracker . StartupTracker . MarkSection ( "mainInitialization" ) ;
753
777
754
778
var app = new IdeStartup ( ) ;
755
- ret = app . Run ( options ) ;
779
+ ret = app . Run ( options , controlMainLoop ) ;
756
780
} catch ( Exception ex ) {
757
781
LoggingService . LogFatalError (
758
782
string . Format (
@@ -761,7 +785,9 @@ public static int Main (string[] args, IdeCustomizer customizer = null)
761
785
BrandingService . ApplicationName
762
786
) , ex ) ;
763
787
} finally {
764
- Runtime . Shutdown ( ) ;
788
+ if ( controlMainLoop ) {
789
+ Runtime . Shutdown ( ) ;
790
+ }
765
791
}
766
792
767
793
LoggingService . Shutdown ( ) ;
0 commit comments