0

Good afternoon,

In my project (not a visual studio addin!), I'm starting Visual Studio 2015 as follows:

Type type = Type.GetTypeFromProgID("VisualStudio.DTE.14.0");
dte = (EnvDTE80.DTE2)Activator.CreateInstance(type);
dte.MainWindow.Visible = true; 
dte.Solution.Open(UserPreferences.Instance.ProjectSlnFilePath);

Now, I've noticed that when I close the IDE, a visual studio background process starts running for some reason. I'm looking for a way to detect when the IDE is being manually closed, in order to kill that background process. I tried to do the following, based on this thread:

dte.Events.DTEEvents.OnBeginShutdown += DTEEvents_OnBeginShutdown;

But it's not triggered. I've tried other events, such as Window_Closing and so on, but nothing seems to work.

Any ideas? Thanks!

Community
  • 1
  • 1
Apidcloud
  • 3,558
  • 2
  • 21
  • 23
  • Possible duplicate of [How to Detect if Visual Studio IDE is closing using VSPackage?](http://stackoverflow.com/questions/14679217/how-to-detect-if-visual-studio-ide-is-closing-using-vspackage) – MethodMan Dec 04 '15 at 18:18
  • It's not a duplicate. I've actually linked that thread, saying it didn't work. – Apidcloud Dec 04 '15 at 18:21
  • 1
    How's that? Doing `EnvDTE.DTEEvents events = dte.Events.DTEEvents; events.OnBeginShutdown += Events_OnBeginShutdown;` is exactly the same - still doesn't work. – Apidcloud Dec 04 '15 at 18:30
  • It cannot close while you got a reference to it. Since you started it, it is up to you to shut it down again. Making it visible is surely not a great idea since that gives the user the expectation that he's in control. But as long as you do, leave him in control and stop using the interface. Best way is to let your program terminate. – Hans Passant Dec 04 '15 at 18:31
  • The user is supposed to use visual studio (he's in control of the IDE). But this way of starting Visual Studio, leaves a background process running when closed manually for some reason. Hence wanting to know when the IDE is about to close. – Apidcloud Dec 04 '15 at 18:34
  • So, the only events that triggered so far are: `dte.Events.WindowEvents.WindowActivated dte.Events.SolutionEvents.Opened` Closing solution events don't seem to work either... – Apidcloud Dec 04 '15 at 21:34

0 Answers0