对一个Windows应用程序处理结束进程 [英] Handling end process of a windows app

查看:183
本文介绍了对一个Windows应用程序处理结束进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能捕捉到相同的Windows应用程序本身的一个Windows应用程序的任务管理器结束进程?我使用的是C#2.0的胜利应用程序,我想做些数据库处理(在数据库中更改国旗'Y',以'N')时结束的过程发生。

Is it possible to capture the task manager end process of a windows application within the same windows application itself? I am using a C# 2.0 win app and I would like to do some database processing (change a flag from 'Y' to 'N' in the DB) when an end process happens.

推荐答案

没有,那是不可能的勾操作系统的决定,结束进程。注意,这不是由任务管理器完成,结束了处理是内核的责任。

No, it is not possible to hook the operating system's decision to end a process. Note, this is not done by task manger, ending a process is the responsibility of the kernel.

您需要做两件事情:

  1. 连接事件处理程序来告诉一个应用程序退出普通用户界面消息。使用这些事件中留存数据,免费的资源,并以其他方式退出的。
  2. 在处理异常适当捕获错误和清理,如果可能保存数据。

下面是三个环节,以林峰的博客解释为什么你不能做什么你问。

Here are a three links to Raymond's blog explaining why you cannot do what you are asking.

  • Why can't you trap TerminateProcess?
  • Why do some process stay in Task Manager after they've been killed?
  • The arms race between programs and users

另外,我处理了类似的StackOverflow问题<一href="http://stackoverflow.com/questions/501523/c-deallocate-resources-on-process-termination">here.

Also, I addressed a similar StackOverflow question here.

这篇关于对一个Windows应用程序处理结束进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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