private static void DisplayRestartSettings() { RestartSettings settings = ArrManager.ApplicationRestartSettings( Process.GetCurrentProcess().Handle); Console.WriteLine(settings.ToString()); Console.WriteLine(); }
private static void RegisterForRestart() { // Register for automatic restart if the // application was terminated for any reason // other than a system reboot or a system update. ArrManager.RegisterForApplicationRestart( new RestartSettings( "/restart", RestartRestrictions.NotOnReboot | RestartRestrictions.NotOnPatch)); }
private static void RegisterForRecovery() { RecoverySettings settings = new RecoverySettings( new RecoveryCallback(RecoveryProcedure), new RecoveryData(Environment.UserName), 4000); ArrManager.RegisterForApplicationRecovery( settings); }
// This method is called periodically to ensure // that WER knows that recovery is still in progress. private static void PingSystem() { // Find out if the user canceled recovery. bool isCanceled = ArrManager.ApplicationRecoveryInProgress(); if (isCanceled) { Console.WriteLine("Recovery has been canceled by user."); Environment.Exit(2); } Console.WriteLine(" / "); }
// This method is invoked by WER. private static int RecoveryProcedure(RecoveryData parameter) { Console.WriteLine("Recovery in progress for {0}", parameter.CurrentUser); // Do recovery work here. for (int i = 0; i < 4; i++) { // Signal to WER that the recovery // is still in progress. PingSystem(); // Simulate long running recovery. System.Threading.Thread.Sleep(3000); } // Indicate that recovery work is done. Console.WriteLine("Application shutting down..."); ArrManager.ApplicationRecoveryFinished(true); return(0); }