Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching the application exit event while in Debug mode?

Status
Not open for further replies.

emblewembl

Programmer
May 16, 2002
171
GB
My C# Windows app has to connect to a computer when requested by a user, and therefore it is important that I ensure this connection is 'cleaned up' whenever the application closes, whether it is manually closed or crashes etc.

All of this is fine apart from when I am running the application from Visual Studio.Net 2003 in debug mode and I press shift + F5 to stop debugging. The Application Dispose method does not get called in this scenario and I have tried catching Application.ThreadExit, Application.Exit etc but can't seem to find any event that is fired in this case.

It is important that I can catch some event because connections are being left open and I eventually run out which is a real pain!! Any ideas?

i love chocolate
 
I haven't tried it but will the System.Diagnostics.Process.GetCurrentProcess().Exited event give you what you want ?
 
I've tried what you said but that event isn't caught either. Thanks for the suggestion though. Any other ideas?

i love chocolate
 
I've had a quick flick through the documentation, but I'm not sure you will be able to achieve what you want. If I understand you correctly, you want to execute some clean up code after the program execution is halted by the attached debugger (i.e. VS). Given that the attached debugger stops the program execution abruptly, it is unlikely that you will be able to execute code beyond that point.

You may be able to extend the VS environment (using the DTE object model and hooking into one of the DebuggerEvents such as OnEnterBreakMode) and clean up the connection after a period of inactivity, but I have no experience of doing this, and don't really know if it will be possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top