How to detect a Kill Process event

懵懂的女人 提交于 2019-11-28 06:35:08

问题


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!


回答1:


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

None
WindowsShutDown
MdiFormClosing
UserClosing
TaskManagerClosing
FormOwnerClosing
ApplicationExitCall



回答2:


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!



来源:https://stackoverflow.com/questions/1372250/how-to-detect-a-kill-process-event

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!