Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exit an ASP.NET application gracefully when stopping debugging in VS 2010?

I develop and debug an ASP.NET application with VS 2010. My ASP.NET application holds some connections to other applications on other machines. When I stop debugging, I want these connections to be released. If this doesn't happen, these other applications fail and I have to restart them.

In the end I will store my termination code in the Application_End method in Global.asax.cs, but this one is not called when stopping debugging.

Is there a way to terminate the debugging of my ASP.NET application so that not everything is killed at once, but so that one last method is called in which I could add my termination code?

like image 776
Rob Lu Avatar asked Nov 04 '22 08:11

Rob Lu


2 Answers

I'm not sure what your problem is but probably...

You initialize your debug session by pressing F5 and thus debugging through cassini. This way when you end your debug session the application is terminated.

If you have a configured IIS application you could simply attach to the running process - it's usually "CTRL + ALT + P" - choosing w3wp.exe (mind the checkboxes on the bottom to be checked). This way your app won't be terminated on ending the debugging session.

Does it solve your problem?

like image 147
ub1k Avatar answered Nov 09 '22 11:11

ub1k


I misunderstood how debugging an ASP.NET application works. I thought the moment I stop debugging (by pressing Shift+F5) the ASP.NET application is terminated and no further line of code is executed. It was my explanation to why the Application_End method is not called.

But in fact the ASP.NET application goes on when the debugger is detached and therefore the Application_End method is not called.

like image 36
Rob Lu Avatar answered Nov 09 '22 10:11

Rob Lu