public static void RegisterForRecovery()
 {
     // Since this registration is being done on application startup, we don't have a state currently.
     // In some cases it might make sense to pass this initial state.
     // Another approach: When doing "auto-save", register for recovery everytime, and pass
     // the current state I.E. data for recovery at that time. 
     RecoveryData data = new RecoveryData(new RecoveryCallback(RecoveryProcedure), null);
     RecoverySettings settings = new RecoverySettings(data, 0);
     ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(settings);
 }
        public static void RegisterForRecovery()
        {
            // Since this registration is being done on application startup, we don't have a state currently.
            // In some cases it might make sense to pass this initial state.
            // Another approach: When doing "auto-save", register for recovery everytime, and pass
            // the current state I.E. data for recovery at that time.
            RecoveryData     data     = new RecoveryData(RecoveryProcedure, null);
            RecoverySettings settings = new RecoverySettings(data, 0);

            RegisterForApplicationRecovery(settings);
        }
        /// <summary>
        /// Registers an application for recovery by Application Restart and Recovery.
        /// </summary>
        /// <param name="settings">An object that specifies the callback method, an optional parameter to pass to the callback
        /// method and a time interval.</param>
        /// <remarks>The time interval is the period of time within which the recovery callback method calls
        /// the ApplicationRecoveryInProgress method to indicate that it is still performing recovery work.</remarks>
        private static void RegisterForApplicationRecovery(RecoverySettings settings)
        {
            if (OSVersion.IsAboveOrEqual(WindowsVersion.Vista))
            {
                if (settings == null)
                {
                    throw new ArgumentNullException("settings");
                }

                GCHandle handle = GCHandle.Alloc(settings.RecoveryData);

                HResult hr = AppRestartRecoveryNativeMethods.RegisterApplicationRecoveryCallback(AppRestartRecoveryNativeMethods.internalCallback, (IntPtr)handle, settings.PingInterval, (uint)0);

                switch (hr)
                {
                case HResult.InvalidArgument:
                    throw new ArgumentException("Application was not registered for recovery due to bad parameters.");

                case HResult.Fail:
                    throw new ExternalException("Application failed to register for recovery.");
                }
            }
        }
        /// <summary>
        /// Registers an application for recovery by Application Restart and Recovery.
        /// </summary>
        /// <param name="settings">An object that specifies the callback method, an optional parameter to pass to the callback
        /// method and a time interval.</param>
        /// <remarks>The time interval is the period of time within which the recovery callback method calls 
        /// the ApplicationRecoveryInProgress method to indicate that it is still performing recovery work.</remarks>
        private static void RegisterForApplicationRecovery(RecoverySettings settings)
        {
            if (OSVersion.IsAboveOrEqual(WindowsVersion.Vista))
            {
                if (settings == null)
                    throw new ArgumentNullException("settings");

                GCHandle handle = GCHandle.Alloc(settings.RecoveryData);

                HResult hr = AppRestartRecoveryNativeMethods.RegisterApplicationRecoveryCallback(AppRestartRecoveryNativeMethods.internalCallback, (IntPtr)handle, settings.PingInterval, (uint)0);

                switch (hr)
                {
                    case HResult.InvalidArgument:
                        throw new ArgumentException("Application was not registered for recovery due to bad parameters.");
                    case HResult.Fail:
                        throw new ExternalException("Application failed to register for recovery.");
                }
            }
        }
 public static void RegisterForRecovery()
 {
     RecoveryData data = new RecoveryData(new RecoveryCallback(RecoveryProcedure), null);
     RecoverySettings settings = new RecoverySettings(data, 0);
     ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(settings);
 }