3

I'm looking for a way to execute a method on stop debugging in an ASP.NET web application.

I have several resource releases methods that I have to execute in any way the application shuts down. (Including stop debugging (kill))

I've tried Application_End and overriding Dispose() in global.asax but they are not executing on stop debugging. Either AppDomain.CurrentDomain.ProcessExit event.

Actually it makes sense any method can not be executed while we kill the process but it might be a creative way to do so.

Jacob
  • 3,598
  • 4
  • 35
  • 56
  • Does this answer your question? [Stop Debugging Event in C#](https://stackoverflow.com/questions/11023944/stop-debugging-event-in-c-sharp) – tiberriver256 Apr 05 '22 at 22:46

2 Answers2

2

You can't handle termination of the process from the same process which you are terminating.

To perform any tasks on stop debugging you will need another method which observes the process and executes required functions when the first process terminates.

Abhishek Maurya
  • 321
  • 1
  • 3
  • 13
0

Other community members also asked this issue before, Abhishek Maurya's answer would be correct, "stop Debugging" terminates the process you are debugging, so it has no code will run in your app.

One workaround is that you could write a visual studio add-in.

Reference:

Stop Debugging Event in C#

Community
  • 1
  • 1
Jack Zhai
  • 6,230
  • 1
  • 12
  • 20
  • In the case of ASP.NET app "Stop debugging" doesn't stop the process, but detaches the debugger. The process (w3wp.exe) continues to execute. – SergeyT Jun 25 '20 at 00:27