/// <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);
			}
		}
Exemple #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);
            }
        }