views:

136

answers:

1

I'm writing a VS2008 add-in (using DTE) that needs to be notified after the current solution has finished loading.

I've tried using the following code:

events = (Events2) applicationObject.Events
events.SolutionEvents.Opened += DoSomeWorkEvent;

Unfortunately it seems that since VS2005 the event is thrown when the solution starts to load - and not when it finishes.

A short internet search produced the following thread that explains the problem and suggest a solution (check each project item to see if it finished loading).

Is this the best solution available or is there a better way to know when a solution has finished loading?

+2  A: 

I've found a workaround that solves this problem - I've created a Windows.Forms.Timer that runs on the main thread and checks if the solution has finished loading.

private void TimerTick(object sender, EventArgs e)
{
   try
   {
       var solution = applicationObject.Solution;
       if (solution.IsOpen && string.IsNullOrEmpty(solution.FileName) == false)
       {
           timer.Stop();
           // insert logic here
       }
   }
   catch (Exception exception)
   {
       Console.WriteLine(exception);
   }
}
Dror Helper