即使在进程kill保证code执行 [英] Guarantee code execution even on process kill

查看:115
本文介绍了即使在进程kill保证code执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在这个过程停止执行的code(状态保存)的部分 - 本身,用户,通过任务管理器等

I need to execute a portion of code (the state save) on the process stopping - by itself, by user, by task manager, etc.

这可能吗?

尝试{}终于{} AppDomain.ProcessExit 的IDisposable ,析构函数,..下一步要试试吗?

try {} finally {}, AppDomain.ProcessExit, IDisposable, destructor,.. what next to try?

推荐答案

正如其他人所指出的那样,没有办法,你可以在你的应用程序中执行任何code当它被操作系统用户。这就是为什么它被称为

As others have pointed out, there is no way you can execute any code in your application when it is being Killed by Operating System or User. That is why its called Killing.

如果保存状态是应用程序的一个重要组成部分,你应该采取类似于数据库系统的方法。实施事务日志,创建检查站,等等。这是最接近你可以得到的。

If saving the state is an important part of your application, you should take an approach similar to a database system. Implementing transaction log, creating checkpoints, etc. That is the closest you can get.

在这种情况下,当你的应用程序复苏,它可以检查这些事务日志重新运行) $ C>为所有未处理的更新或最后状态的变化。

In that case, when your application revives (is re-run after being killed), it can check these transaction logs for any pending updates or last state changes.

除此之外,它真的取决于你想要做什么。而也就是为什么你有这样的想法来到了?我们可以得到更多的细节?可能是有人在这里有更好的选择。

Other than that, it really depends on what you want to do. And also why you came up with this idea? Can we get more details? May be someone here has better alternative.

这篇关于即使在进程kill保证code执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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