如何检测终止进程事​​件

发布于 2024-08-03 22:13:11 字数 112 浏览 3 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撕心裂肺的伤痛 2024-08-10 22:13:11

如果是winform,可以捕获FormClosing事件并检查CloseReason

None
WindowsShutDown
MdiFormClosing
UserClosing
TaskManagerClosing
FormOwnerClosing
ApplicationExitCall

if it's a winform, you can capture the event FormClosing and check the CloseReason:

None
WindowsShutDown
MdiFormClosing
UserClosing
TaskManagerClosing
FormOwnerClosing
ApplicationExitCall
不知所踪 2024-08-10 22:13:11

虽然可以使用代码注入、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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文