Execute code when application exits

Bufedog

Member
Joined
Nov 20, 2006
Messages
16
Programming Experience
1-3
I have an application that runs in the background. Unfortunately, it cannot be a service because it needs to use login forms.

However, I need to know if it is ended and write that to a log so that I know when, and hopefully why it was ended. Anyone have any idea how I would go about doing that?
 
Handle the forms FormClosing event (or FormClosed) and check e.CloseReason.
 
What kind of application is this? If you run message loop through the Application object it has the shared ApplicationExit event. If this is a Console application you can use the SetConsoleCtrlHandler (see example)
 
It's not a console application. It is a Windows Application that runs from a main method in a class. It routinely checks for the existence of a list of files it gets from an XML document. Then it prompts for a user name and password from Server Room Personnel (The login form is why the application is not a windows service). When they input the username and password, the program FTP's the file to is predetermined destination.

I need a way of knowing if this application is closed from the task manager.
 
Back
Top