/// <summary>Initializes the singleton instance of the command.</summary> /// <param name="package">Owner package, not null.</param> /// <returns>A task representing the async work of command initialization.</returns> public static async System.Threading.Tasks.Task InitializeAsync(ThemeSwitcherPackage package) { OleMenuCommandService menuCommandService; // Switch to the main thread - the call to AddCommand in Command1's constructor requires // the UI thread. await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); #pragma warning disable VSSDK006 // Check services exist menuCommandService = (OleMenuCommandService)await package.GetServiceAsync(typeof(IMenuCommandService)).ConfigureAwait(continueOnCapturedContext: false); #pragma warning restore VSSDK006 // Check services exist Instance = new SwitchThemeAndWindowLayoutCommand(package, menuCommandService); }
/// <summary> Initializes a new instance of the <see cref="SwitchThemeAndWindowLayoutCommand" /> class.</summary> /// <param name="package">Owner package.</param> /// <param name="menuCommandService">The service to manage the menu commands.</param> /// <exception cref="ArgumentNullException">Occurs if any of the parameters is null.</exception> private SwitchThemeAndWindowLayoutCommand(ThemeSwitcherPackage package, OleMenuCommandService menuCommandService) { if (package == null) { throw new ArgumentNullException(nameof(package)); } if (menuCommandService == null) { throw new ArgumentNullException(nameof(menuCommandService)); } this.package = package; menuCommandService.AddCommand(new MenuCommand(this.MenuItemCallback, new CommandID(CommandSet, CommandId))); }