如何检测终止进程事件
在 C# 中,我使用 process.Kill() 杀死一个进程, 同时在被杀死的应用程序中如何检测此事件?
顺便说一句:Application.ApplicationExit 事件尚未被触发!
In C# i using process.Kill() kill a process,
at the same time in killed application how to detect this event?
BTW: Application.ApplicationExit event has not been fired!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果是winform,可以捕获
FormClosing
事件并检查CloseReason
:if it's a winform, you can capture the event
FormClosing
and check theCloseReason
:虽然可以使用代码注入、API 挂钩和许多其他技术来实现这一目标,但没有简单的方法可以实现这一目标,但我向您提出的问题是,您真的想要进行大量额外的工作吗?只是为了确保您的应用程序知道意外终止?您必须确保您编写了注入/挂钩(或您选择的任何方法)其他人可以用来终止您的应用程序的每一种可能的方法,当有人确实进行这些调用之一时,您的应用程序可以触发自己的事件,表明它应该处理此类事件并准备退出。本质上,您还可以使用它来阻止其他人也能够关闭您的应用程序。
如果您想了解有关这些技术的更多信息,请告诉我,我将发布一些链接。祝你好运!
There are no simple ways of accomplishing this, though code injecting, api hooking, and a number of other techniques could be used to accomplish this very goal, but my question to you is, do you really want to go through a lot of extra work just to make sure your application is aware of an unexpected termination? You would have to ensure that you code injected/hooked (or whatever method your chose) every single possible method someone else could use to terminate your application, when someone does make one of those calls your application can trigger its own event indicating that it should process such an event and prepare to exit. Essentially you could also use this to stop anyone else from being able to close your application as well.
If you want more information about any of these techniques let me know and I'll post some links. Good luck!