Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
598 views
in Technique[技术] by (71.8m points)

.net - 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();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...