应用程序退出日志 [英] Application exit log

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

问题描述

大家好,

我创建了一个Windows窗体应用程序,我需要在应用程序退出时写一个日志文件。我使用了表单关闭事件,但如果使用任务管理器或注销关闭应用程序,则编码不起作用。任何机构都可以为此提供解决方案吗?。

解决方案

不,不可能挂钩操作系统结束进程的决定。注意,这不是由任务管理器完成的,结束一个过程是内核的责任。



你需要在这里做两件事:



1.将事件处理程序连接到告诉应用程序退出的普通用户界面消息。使用这些事件来保存数据,释放资源,以及以其他方式彻底退出。

2.处理异常以捕获错误并尽可能清理和保存数据。

这里是雷蒙德博客的三个链接,解释了为什么你不能做你想要的。



为什么不能捕获TerminateProcess? [ ^ ]

为什么有些进程在被杀后会留在任务管理器中? [ ^ ]

程序和用户之间的军备竞赛 [ ^ ]



资料来源: 处理Windows应用的最终流程 [ ^ ]

Hi all,
I have created one windows form application, I need to write a log file on application exit. I used the form closing event, but if the application is closed using task manager or logoff then the coding is not working. Can any body have a solution for this?.

解决方案

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.

You will need to do two things here:

1. Connect event handlers to the normal user interface messages that tell a application to exit. Use these events to persist data, free resources, and otherwise exit cleanly.
2. Handle exceptions as appropriate to catch errors and clean up and save data if possible.
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[^]

Source: Handling end process of a windows app[^]


这篇关于应用程序退出日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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