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

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

问题描述

我有一个WPF应用程序偶尔崩溃,并说不回应。有没有办法检测程序是否没有响应?如果是这样,请重新启动WPF应用程序?



这将是一个临时修复,直到错误被修复。

解决方案

你可以使用Application Recovery& Restart Manager API,在Windows Vista中引入。这是一个非托管(C)API,但是在 Windows API代码包中可以使用托管包装器。



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



API的最基本用法是只需在应用程序启动中添加以下行:

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


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?

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

解决方案

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.

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天全站免登陆