protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { CommandID cmd = null; MenuCommand menuCmd = null; cmd = new CommandID(GuidList.guidBookmarkCmdSet, CommandIdIcmdBookmarkAddCommand); menuCmd = new MenuCommand(new EventHandler(OnBookmarkAddCommand), cmd); mcs.AddCommand(menuCmd); cmd = new CommandID(GuidList.guidBookmarkCmdSet, CommandIdIcmdBookmarkDelCommand); menuCmd = new MenuCommand(new EventHandler(OnBookmarkDelCommand), cmd); mcs.AddCommand(menuCmd); cmd = new CommandID(GuidList.guidBookmarkCmdSet, CommandIdIcmdBookmarkOptCommand); menuCmd = new MenuCommand(new EventHandler(OnBookmarkOptCommand), cmd); mcs.AddCommand(menuCmd); } bool isSolutionLoaded = await IsSolutionLoadedAsync(); if (isSolutionLoaded) { SolutionEvents.OnAfterBackgroundSolutionLoadComplete += HandleOpenSolution; } // Listen for subsequent solution events await ToolWindowCommand.InitializeAsync(this); }
/// <summary> /// Initializes the singleton instance of the command. /// </summary> /// <param name="package">Owner package, not null.</param> public static async Task InitializeAsync(AsyncPackage package) { // Switch to the main thread - the call to AddCommand in ToolWindowCommand's constructor requires // the UI thread. await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService; Instance = new ToolWindowCommand(package, commandService); }