Question

I'm writing a system tray Winforms app which does some very important cleanup on Application.ApplicationExit. When I hit the stop button while debugging in Visual Studio, this the process exits, but this cleanup code doesn't get called. Is there some way I can make sure it gets called in this situation?

Was it helpful?

Solution

No. When you hit the stop button you can expect your application to not execute anymore code (this allows you to exit infinite loops). If it executed more code, then the stop button would be a close button. The stop button allows you to kill your application without having to open taskman, which would likely kill VS also.

I would suggest having a close menu item on a context menu for the icon. When the user clicks it, your app would close & clean-up, allowing your program to exit gracefully.

If you want more information about the stop debugging button check out the MSDN reference on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top