Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Debugging Event in C#

How or where can I run a command when the application closes, even if is a debug stop?

I need to perform a command in any exit, even if the user is a developer and click on "stop debugging" button on Visual Studio.

I try with

Application.ApplicationExit += new EventHandler(this.OnApplicationExit);

but it doesn't work. Maybe I'm wrong or is not the event.

I'm using Winforms and not, on Form Close can't be the event.

I'm using Visual Studio 2005 Net Framework 2.0 (by client requirement), but is just for information.

Maybe can I rewrite this?:

public static void Exit();
like image 872
Leandro Bardelli Avatar asked Jun 13 '12 21:06

Leandro Bardelli


People also ask

How do I stop debugging?

In order to stop the debugger, try two things: Click on Tools > Web Developer > and make sure Debugger is not checked. Toggle the tools instead > Click on "Debugger" and click on the gear in the right corner and uncheck "Show on Startup"

How do I stop debugging in CMD?

Click Stop Debugging on the Debug menu to stop the target's execution and end the target process and all its threads. This action enables you to start to debug a different target application. )

How do I stop debugging in Visual Basic?

To end a debugging session in Microsoft Visual Studio, from the Debug menu, choose Stop Debugging.


2 Answers

The problem is the "stop debugging" function will halt the application entirely - so no more code within that application will run.

Your only way of achieving this would be to watch the process being debugged externally and execute the code if it has been halted.

According to [MSDN]:

Stop Debugging terminates the process you are debugging if the program was launched from Visual Studio.

However you may be able to achieve what you want with a visual studio add-in.

like image 60
m.edmondson Avatar answered Sep 20 '22 20:09

m.edmondson


According to MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.applicationexit%28v=vs.80%29.aspx

// Handle the ApplicationExit event to know when the application is exiting.
Application.ApplicationExit += new EventHandler(this.OnApplicationExit);

private void OnApplicationExit(object sender, EventArgs e) {
// When the application is exiting
}

Is this what you implemented?

like image 28
Mausimo Avatar answered Sep 18 '22 20:09

Mausimo