Responding to Visual Studio Stop

Is it possible to run some code when the code stops when it is run from Visual Studio?

I am using the CefGlue library to create a WinForms application and realized that there are problems when clicking the stop button from Exception to two windows without opening the contents. A separate process continues to run in the background. To terminate Cef, I need exectue CefRuntime.Shutdown(); Perhaps this is due to the fact that it does not start the application while hosting Visual Studio, because CefGlue has problems with this (see this ). This does not affect production, but it is unpleasant in development and testing, but nevertheless I would like to execute some code to fix this problem.

I would suggest that this is impossible, but it would be interesting to know.

So, I'm looking for a way to execute some code when Visual Studio stops the application when the stop button is pressed during development.

Note. I am using Visual Studio 2013 and 2015.

Edit The problem is not reproducible with very few lines of code. However, I tried to create a simplified example here

+5
source share
1 answer

What you are mostly looking for is a solution using the Visual Studio SDK.

You can create your own add-ons by implementing the IDTExtensibility interface .

In the OnConnection function, you can subscribe to various events. Using the (DTE2)application , you can access from several things from VS.

You need to subscribe to some of the events that can be obtained from the Events property.

You will need to find out which events are best for your decision. But DebuggerEvents would seem like a good place to start.

This requires some research before you can use it. Most likely, there will be simpler solutions.

As a simple example for OnConnection :

 public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { var applicationObject = (DTE2)application; var events = _applicationObject.Events; var buildEvents = (BuildEvents)events.BuildEvents; buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(OnBuildBegin); } 

This works when the build starts. The documentation available is small, so you will need a trial version and errors before you find what you need.

+1
source

Source: https://habr.com/ru/post/1241584/


All Articles