Wednesday, March 16, 2011

Adding Restart/Recovery capability to your app's with "Windows Restart and Recovery Recipe" code recipe from MSDN Code Gallery

MSDN Code Gallery - Windows Restart and Recovery Recipe

"Windows 7 includes two closely related features: Application Restart and Application Recovery. These features are designed to eliminate much of the pain caused by the unexpected termination of applications, whether as a result of an unhandled exception, a “hard hang,” or an external request that is part of updating a DLL or other resource in use by the application.

Application Recovery applies to applications that have a “document” or any other in-memory information that might be lost when the application closes unexpectedly, such as when an unhandled exception is thrown.Application Restart applies to all applications, whether they might have unsaved data or not, and to more unexpected closes, including a DLL update or a system reboot.

Any Windows application can register with the operating system for restart, and optionally for recovery.

  • To register for recovery, the application provides a callback function. The operating system will call this function on a separate thread (remember, your main thread just throw an exception) if the application crashes or hangs. The callback function can save any unsaved data in a known location. It cannot access the UI thread, which is no longer running. Do note, that the call back function cant run forever. The OS will not permit it to run more than few seconds.
  • To register for restart, the application provides a command line argument that will inform the application it is restarting. A restarted application that uses recovery can look in the known location for recovery data when it is restarted, and reload the unsaved data.

This recipe provide guidance and an easy way to start using these great features in your application, removing any complication of how and where to store your application data.

What’s in the box?

This Restart and Recovery recipe includes:

  • Complete source code of the recipe and its samples
  • Managed .NET assembly
  • C++ header and class files to be included in your C++ application.
  • C#, and C++ test applications
  • Documentation


App crashes and reboots byte, but you can make them byte a little less in Windows 7 by using the App Recovery and Reboot feature. This simple recipe shows you how...

Here's a thumbnail view of the included 14 page docx;


And a snap of the solution;


No comments: