/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { this.GetLogger().LogInformation(this.GetPackageName(), "Initializing."); base.Initialize(); try { var visualStudioProcess = Process.GetCurrentProcess(); this.otherApplicationFocusedHandlerReference = this.HandleOtherApplicationFocused; this.currentInstanceFocusedHandlerReference = this.HandleCurrentInstanceFocused; this.otherApplicationFocusedHookHandle = WindowsEventHooker.SetWinEventHook(3, 3, IntPtr.Zero, this.otherApplicationFocusedHandlerReference, 0, 0, SetWinEventHookFlags.WINEVENT_OUTOFCONTEXT | SetWinEventHookFlags.WINEVENT_SKIPOWNPROCESS); this.currentInstanceFocusedHookHandle = WindowsEventHooker.SetWinEventHook(3, 3, IntPtr.Zero, this.currentInstanceFocusedHandlerReference, (uint)visualStudioProcess.Id, 0, SetWinEventHookFlags.WINEVENT_OUTOFCONTEXT); var dte = (DTE)this.GetService(typeof(DTE)); this.solutionEvents = dte.Events.SolutionEvents; this.solutionEvents.BeforeClosing += this.HandleBeforeClosingSolution; this.solutionEvents.Opened += this.HandleSolutionOpened; this.GetLogger().LogInformation(this.GetPackageName(), "Initialized."); } catch (Exception exception) { this.GetLogger().LogError(this.GetPackageName(), "Exception during initialization", exception); } }
protected override void Dispose(bool disposing) { this.GetLogger().LogInformation(this.GetPackageName(), "Disposing."); WindowsEventHooker.UnhookWinEvent(this.currentInstanceFocusedHookHandle); this.currentInstanceFocusedHandlerReference = null; WindowsEventHooker.UnhookWinEvent(this.otherApplicationFocusedHookHandle); this.otherApplicationFocusedHandlerReference = null; this.GetLogger().LogInformation(this.GetPackageName(), "Disposed."); base.Dispose(disposing); }