我有一个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 ) );
相关推荐
最新文章