/// <include file='doc\OleMenuCommandService.uex' path='docs/doc[@for="OleMenuCommandService.OnCommandChanged"]/*' /> /// <devdoc> /// This is called by a menu command when it's status has changed. /// </devdoc> protected override void OnCommandsChanged(MenuCommandsChangedEventArgs e) { base.OnCommandsChanged(e); if (0 == _queryStatusCount) { // UpdateCommandUI(0) can not be called inside QueryStatus because this will cause an infinite // sequence of calls to QueryStatus during idle time. IVsUIShell uiShellSvc = null; try { uiShellSvc = GetService(typeof(SVsUIShell)) as IVsUIShell; } catch (Exception) { // The command change notifications may come at shutdown time after COM has been terminated if a package or addin // chooses to remove menu commands from an object finalizer (the finalizer thread runs after COM shutdown, too). // Any access to shell services at that point will cause System.InvalidComObjectException, System.AccessViolationException // or System.Runtime.InteropServices.COMException(RPC_E_DISCONNECTED) because the RCW for the service provider // has been disconnected from the underlying COM object. // Instead of crashing, catch exceptions around getting the shell service, and skip updating the UI. // Continue to throw if there were problems obtaining the shell service when running on the UI thead (as the function should normally be invoked). if (IsCurrentThreadMainUIThread()) { throw; } } if (uiShellSvc != null) { NativeMethods.ThrowOnFailure(uiShellSvc.UpdateCommandUI(0)); } } }
protected virtual void OnCommandsChanged(MenuCommandsChangedEventArgs e) { if (MenuCommandsChanged != null) { MenuCommandsChanged(this, e); } }
/// <include file='doc\OleMenuCommandService.uex' path='docs/doc[@for="OleMenuCommandService.OnCommandChanged"]/*' /> /// <devdoc> /// This is called by a menu command when it's status has changed. /// </devdoc> protected override void OnCommandsChanged(MenuCommandsChangedEventArgs e) { base.OnCommandsChanged(e); if (0 == _queryStatusCount) { // UpdateCommandUI(0) can not be called inside QueryStatus because this will cause an infinite // sequence of calls to QueryStatus during idle time. IVsUIShell uiShellSvc = GetService(typeof(SVsUIShell)) as IVsUIShell; if (uiShellSvc != null) { NativeMethods.ThrowOnFailure(uiShellSvc.UpdateCommandUI(0)); } } }
protected override void OnCommandsChanged(MenuCommandsChangedEventArgs e) { base.OnCommandsChanged(e); this.OnMenuCommandStatusChanged(); }