icrosoft has gone to great lengths to help you make your software applications more appealing to users. You can create rich user experiences with Windows Presentation Foundation, smooth web applications with ASP.NET AJAX, data friendly applications with LINQ, and much more. But when it comes to appeal, nothing beats an application that is always available and doesn't suffer from data loss or corruption. Microsoft's Application Recovery and Restart (ARR) API makes it easier than ever to add this level of appeal to your application. ARR gives you an opportunity to recover data and return to a consistent state when your application terminates or hangs, and it will optionally restart your application.
is the process of saving and recovering the state of your application when it terminates unexpectedly or hangs. Application restart
is the process of launching an application after it has terminated unexpectedly. The restart functionality in Application Recovery and Restart is independent of the recovery functionality, but the two complement each other well. You may recover an application without automatically restarting it, and you may automatically restart an application without recovering its data.
Microsoft released ARR with Windows Vista, but it's particularly relevant in Windows Server 2008, because server applications typically require higher reliability and stability, and servers rarely have a human present to address problems when they arise.
To explore ARR, it's easiest to start with an application destined to fail. You'll need Visual Studio 2005 or 2008 running on Windows Vista or Windows Server 2008 to build and run the sample "DevX.ServerApplication" application described in this article. If you haven't yet upgraded to one of these operating systems, but you have an MSDN subscription, you can use Virtual PC 2007 to create a virtual machine test lab.
shows how DevX.ServerApplication exercises the Application Recovery and Restart API.
|Figure 1. DevX.ServerApplication in Action: The sample application exercises the Application Recovery and Restart API.|
DevX.ServerApplication is a .NET console application (see Figure 1
). Microsoft didn't expose Application Recovery and Restart in the .NET Framework, so the first step to using it with .NET is writing a class to expose the relevant kernel32.dll
functions. It turns out that Application Recovery and Restart is one of the more difficult APIs to marshal properly, so you can save valuable time by adding the ApplicationRecoveryRestart class to your application:
public static class ApplicationRecoveryRestart
public delegate Int32 ApplicationRecoveryCallbackDelegate(
public static extern void ApplicationRecoveryFinished(
public static extern Int32 ApplicationRecoveryInProgress(
out Boolean canceled);
public static extern Int32 GetApplicationRecoveryCallback(
out ApplicationRecoveryCallbackDelegate recoveryCallback,
out RecoveryInformation parameter,
out UInt32 pingInterval,
out UInt32 flags);
public static extern Int32 GetApplicationRestartSettings(
ref UInt32 size,
out UInt32 flags);
public static extern Int32 RegisterApplicationRecoveryCallback(
public static extern Int32 RegisterApplicationRestart(
public static extern Int32 UnregisterApplicationRecoveryCallback();
public static extern Int32 UnregisterApplicationRestart();
With the Application Recovery and Restart API exposed to .NET, you're ready to write server applications capable of recovering from failures and restarting.