I have a project that requires that I run some code when the application closes. The application is only a single form that hides itself almost immediately after execution, so the only way it can be closed is by manually terminating it with the task manager.
If I use the onclose event, will it be called in this case? Also, can someone post a brief code example for setting up the onclose event?
Yea – I got dinged when my windows(less) app didn’t shut down with a system shutdown request (you know “terminate this process” type dialog message). You can subscribe to specific requests, for example:
SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_Shutdown);
and the shutdown handler does a clean up (your app) and shutdown:
Application.Exit();
Maybe BFee’s has a better answer.