async Task <int> MainLoop(MonoDevelopOptions options, StartupInfo startupInfo) { ProgressMonitor monitor = new MonoDevelop.Core.ProgressMonitoring.ConsoleProgressMonitor(); monitor.BeginTask(GettextCatalog.GetString("Starting {0}", BrandingService.ApplicationName), 2); //make sure that the platform service is initialised so that the Mac platform can subscribe to open-document events Counters.InitializationTracker.Trace("Initializing Platform Service"); var desktopService = await Runtime.GetService <DesktopService> (); var commandService = await Runtime.GetService <CommandManager> (); // load the global menu for the welcome window to avoid unresponsive menus on Mac desktopService.SetGlobalMenu(commandService, DefaultWorkbench.MainMenuPath, DefaultWorkbench.AppMenuPath); IdeStartupTracker.StartupTracker.MarkSection("PlatformInitialization"); monitor.Step(1); Counters.InitializationTracker.Trace("Checking System"); CheckFileWatcher(); IdeStartupTracker.StartupTracker.MarkSection("FileWatcherInitialization"); Exception error = null; int reportedFailures = 0; try { Counters.InitializationTracker.Trace("Loading Icons"); //force initialisation before the workbench so that it can register stock icons for GTK before they get requested ImageService.Initialize(); IdeStartupTracker.StartupTracker.MarkSection("ImageInitialization"); // If we display an error dialog before the main workbench window on OS X then a second application menu is created // which is then replaced with a second empty Apple menu. // XBC #33699 Counters.InitializationTracker.Trace("Initializing IdeApp"); hideWelcomePage = options.NoStartWindow || startupInfo.HasFiles || IdeApp.Preferences.StartupBehaviour.Value != OnStartupBehaviour.ShowStartWindow; await IdeApp.Initialize(monitor, hideWelcomePage); IdeStartupTracker.StartupTracker.MarkSection("AppInitialization"); if (errorsList.Count > 0) { using (AddinLoadErrorDialog dlg = new AddinLoadErrorDialog(errorsList.ToArray(), false)) { if (!dlg.Run()) { return(1); } } reportedFailures = errorsList.Count; } if (!CheckSCPlugin()) { return(1); } // Load requested files Counters.InitializationTracker.Trace("Opening Files"); // load previous combine RecentFile openedProject = null; if (IdeApp.Preferences.StartupBehaviour.Value == OnStartupBehaviour.LoadPreviousSolution && !startupInfo.HasSolutionFile && !IdeApp.Workspace.WorkspaceItemIsOpening && !IdeApp.Workspace.IsOpen) { openedProject = IdeServices.DesktopService.RecentFiles.MostRecentlyUsedProject; if (openedProject != null) { var metadata = GetOpenWorkspaceOnStartupMetadata(); IdeApp.Workspace.OpenWorkspaceItem(openedProject.FileName, true, true, metadata).ContinueWith(t => IdeApp.OpenFilesAsync(startupInfo.RequestedFileList, metadata), TaskScheduler.FromCurrentSynchronizationContext()).Ignore(); startupInfo.OpenedRecentProject = true; } } if (openedProject == null) { IdeApp.OpenFilesAsync(startupInfo.RequestedFileList, GetOpenWorkspaceOnStartupMetadata()).Ignore(); startupInfo.OpenedFiles = startupInfo.HasFiles; } monitor.Step(1); } catch (Exception e) { error = e; } finally { monitor.Dispose(); } if (error != null) { string message = BrandingService.BrandApplicationName(GettextCatalog.GetString("MonoDevelop failed to start")); message = message + "\n\n" + error.Message; MessageService.ShowFatalError(message, null, error); return(1); } if (errorsList.Count > reportedFailures) { using (AddinLoadErrorDialog dlg = new AddinLoadErrorDialog(errorsList.ToArray(), true)) dlg.Run(); } errorsList = null; AddinManager.AddinLoadError -= OnAddinError; IdeStartupTracker.StartupTracker.MarkSection("BasicInitializationCompleted"); instanceConnection.FileOpenRequested += (sender, a) => { foreach (var e in a) { OpenFile(e.FileName); } }; instanceConnection.StartListening(); IdeStartupTracker.StartupTracker.MarkSection("SocketInitialization"); initialized = true; MessageService.RootWindow = IdeApp.Workbench.RootWindow; Xwt.MessageDialog.RootWindow = Xwt.Toolkit.CurrentEngine.WrapWindow(IdeApp.Workbench.RootWindow); IdeStartupTracker.StartupTracker.MarkSection("WindowOpened"); Thread.CurrentThread.Name = "GUI Thread"; Counters.InitializationTracker.Trace("Running IdeApp"); Counters.InitializationTracker.End(); Counters.InitializationTracker = new NullTimeTracker(); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/InitCompleteHandlers", OnExtensionChanged); StartLockupTracker(); // This call is important so the current event loop is run before we run the main loop. // On Mac, the OpenDocuments event gets handled here, so we need to get the timeout // it queues before the OnIdle event so we can start opening a solution before // we show the main window. await Task.Yield(); IdeStartupTracker.StartupTracker.MarkSection("PumpEventLoop"); IdeStartupTracker.StartupTracker.Stop(startupInfo); GLib.Idle.Add(OnIdle); return(0); }