“优雅地"杀死进程 [英] "Gracefully" killing a process

查看:309
本文介绍了“优雅地"杀死进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用Process.Kill()杀死一个进程.但是,有没有一种方法,而不是立即杀死它,我希望向进程发送一条消息,指示它关闭,以便它可以正常清理和关闭.基本上,我正在寻找等效的方法,只需单击右上角的红色X,我相信确实会向应用程序发送一条消息,要求关闭.

Right now I am using Process.Kill() to kill a process. Is there a way though, instead of just killing it immediately, that I can like send a message to the process instructing it to close so that it can gracefully clean up and shut down. Basically, I'm looking for the equivlent to just clicking the red X in the upper right hand corner, which I believe DOES send a message to the application requesting a shut down.

推荐答案

如果该进程具有Windows界面(如您所指的红色"X"),则可以尝试

If the process has a windows interface (as you refer to the red "X"), you can try Process.CloseMainWindow(). If it fails, you can fallback to Process.Kill().

这篇关于“优雅地"杀死进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆