[英]Run code when current process terminates?
Is there a way to run a bit of code when the current process is getting terminated? 有没有办法在当前进程终止时运行一些代码?
I want to log some stuff when a process terminates (either through external means - eg killing it - or quitting in the application itself). 我希望在进程终止时记录一些东西(通过外部方式 - 例如杀死它 - 或者在应用程序本身中退出)。
We're talking about a Console application written in c#. 我们谈论的是用c#编写的Console应用程序。
Thanks! 谢谢!
看看这里: atexit,在c#中退出委托
I am not sure, but something similar would help 我不确定,但类似的东西会有所帮助
Process process = new Process();
.
.
process.Exited += new EventHandler(myProcess_Exited);
process.Start();
private void myProcess_Exited(object sender, System.EventArgs e)
{
eventHandled = true;
customAction(); // your logging stuff here
}
public void customAction()
{
//
}
have a look at: Process.Exited Event 看看: Process.Exited事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.