/// <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>
        /// <exception cref="System.ArgumentException">
        /// The registration failed due to an invalid parameter.
        /// </exception>
        /// <exception cref="System.ComponentModel.Win32Exception">
        /// The registration failed.</exception>
        /// <remarks>The time interval is the period of time within
        /// which the recovery callback method
        /// calls the <see cref="ApplicationRecoveryInProgress"/> method to indicate
        /// that it is still performing recovery work.</remarks>
        public static void RegisterForApplicationRecovery(RecoverySettings settings)
        {
            // Throw PlatformNotSupportedException if the user is not running Vista or beyond
            CoreHelpers.ThrowIfNotVista();

            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);

            if (!CoreErrorHelper.Succeeded((int)hr))
            {
                if (hr == HRESULT.E_INVALIDARG)
                {
                    throw new ArgumentException("Application was not registered for recovery due to bad parameters.");
                }
                else
                {
                    throw new ExternalException("Application failed to register for recovery.");
                }
            }
        }
Exemplo n.º 2
0
        /// <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>
        /// <exception cref="System.ArgumentException">
        /// The registration failed due to an invalid parameter.
        /// </exception>
        /// <exception cref="System.ComponentModel.Win32Exception">
        /// The registration failed.</exception>
        /// <remarks>The time interval is the period of time within 
        /// which the recovery callback method 
        /// calls the <see cref="ApplicationRecoveryInProgress"/> method to indicate
        /// that it is still performing recovery work.</remarks>        
        public static void RegisterForApplicationRecovery(RecoverySettings settings)
        {           
            CoreHelpers.ThrowIfNotVista();

            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);

            if (!CoreErrorHelper.Succeeded(hr))
            {
                if (hr == HResult.InvalidArguments)
                {
                    throw new ArgumentException(LocalizedMessages.ApplicationRecoveryBadParameters, "settings");
                }

                throw new ApplicationRecoveryException(LocalizedMessages.ApplicationRecoveryFailedToRegister);
            }
        }