DCSIMG

 Subscribe in a reader

Hooking Up to the Solution Events - Guy kolbis
Thursday, November 22, 2007 1:24 PM kolbis

Hooking Up to the Solution Events

I have been working on creating an Add-In to Visual Studio. One of the things I was trying to do is hooking to several solution related events such as Solution Opened and Solution After Closing.

The solution opened event Occurs immediately after opening a solution or project.

The solution after closing event Occurs immediately closing closing a solution.

You can read more about the events here.

So, while trying to connect to the opened event, I wrote this code:

_applicationObject.Events.SolutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(sec_Opened);

This looks fairly simple. The _applicationObject is the DTE2 object that we get in the OnConnection event handler. The problem was that when I opened a solution the event did not fire!

After plaing with it for a while I found out that we need to be careful where and how we declare the event. I solved it by declaring the events as class members. Here is what worked for me:

// Declare the variables at the class scope
private Events2 events;

private SolutionEvents solutionEvents;

// Use it somewhere in code
events = (Events2)_applicationObject.Events;

solutionEvents = events.SolutionEvents;

solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(sec_Opened); תגים:,

תוכן התגובה

# re: Hooking Up to the Solution Events

Nate Shaw כתב/ה

I was caught by the same problem, and solved it in a similar way.

Friday, January 18, 2008 7:26 AM

# Inferis’ Mind Dump » Blog Archive » links for 2008-05-13

Pingback from  Inferis’ Mind Dump  » Blog Archive   » links for 2008-05-13

Wednesday, May 14, 2008 1:36 AM

# VSX tips 1??? don’t make EnvDTE80.Events2 a local variable « Carl Zhang's Blog

Pingback from  VSX tips 1??? don’t make EnvDTE80.Events2 a local variable « Carl Zhang's Blog

Wednesday, April 14, 2010 10:25 AM

# re: Hooking Up to the Solution Events

riezebosch כתב/ה

Blogged about Solution Events and #VS11 AddIns: blogs.infosupport.com/solution-events-in-vs11-addins

Tuesday, April 17, 2012 6:44 PM

שלח תגובה

(שדה חובה) 
(שדה חובה) 
(אופציונלי)
(שדה חובה) 

Enter the numbers above: