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?
views:
210answers:
1
+2
A:
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.
Lucas McCoy
2009-08-04 17:46:55
Yes I have a close context button. The real problem is that when the app fails to close gracefully, it leaves a partially mounted virtual disk active which makes Windows unstable.
mcintyre321
2009-08-04 23:50:44
**@mcintyre321:** Why can't you just hit the close context button? It would seam easier then trying to turn the stop debugging button into something that it's not meant to be.
Lucas McCoy
2009-08-05 19:12:50
sometimes it becomes a bit unresponsive!
mcintyre321
2009-08-06 11:04:21