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?
在显示表单之前,在Program.cs中添加以下内容:
Application.Exit += ....
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.