如果WPF应用程序没有响应,则自动重启 [英] if wpf app is not responding, then auto restart

查看:977
本文介绍了如果WPF应用程序没有响应,则自动重启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序,偶尔死机,并说:没有响应。有没有一种方法来检测,如果该程序没有响应?如果是的话,重新启动WPF应用程序?

I have a WPF application that occasionally crashes, and say "not responding". Is there a way to detect if the program is not responding? And if so, restart the WPF application?

这将是一个临时的解决办法,直到bug被修复。

This will be a temporary fix until the bugs are fixed.

推荐答案

您可以使用应用程序恢复和放大器;重启管理器API,这是Windows Vista中引入。这是一个非托管(C)API,在的Windows API code可用但也有托管包装包

You could use the Application Recovery & Restart Manager API, which was introduced in Windows Vista. This is an unmanaged (C) API, however there are managed wrappers available in the Windows API Code Pack.

这是一个很好的功能添加到您的应用程序,无论如何,因为它提供了一个更好的经验,如果(当!)你的应用程序崩溃的用户。你甚至可以编写一个回调,仍然存在关于用户在做什么的信息,然后恢复状态,当应用程序重新启动。

This is a good feature to add to your application anyway, as it provides the user with a nicer experience if (when!) you application crashes. You can even write a callback that persists information about what the user was doing, and then restore that state when the application restarts.

最基本的使用API​​将只是某个地方加入下面的行应用程序的启动:

The most basic use of the API would be to just add the following line somewhere in application startup:

ApplicationRestartRecoveryManager.RegisterForApplicationRestart( new RestartSettings( "restart", RestartRestrictions.None ) );

这篇关于如果WPF应用程序没有响应,则自动重启的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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