示例#1
0
        /// <summary>
        /// Registers an application for automatic restart if
        /// the application
        /// is terminated by Windows Error Reporting.
        /// </summary>
        /// <param name="settings">An object that specifies
        /// the command line arguments used to restart the
        /// application, and
        /// the conditions under which the application should not be
        /// restarted.</param>
        /// <exception cref="System.ArgumentException">Registration failed due to an invalid parameter.</exception>
        /// <exception cref="System.InvalidOperationException">The attempt to register failed.</exception>
        /// <remarks>A registered application will not be restarted if it executed for less than 60 seconds before terminating.</remarks>
        public static void RegisterForApplicationRestart(RestartSettings settings)
        {
            // Throw PlatformNotSupportedException if the user is not running Vista or beyond
            CoreHelpers.ThrowIfNotVista();
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            HResult hr = AppRestartRecoveryNativeMethods.RegisterApplicationRestart(settings.Command, settings.Restrictions);

            if (hr == HResult.Fail)
            {
                throw new InvalidOperationException(LocalizedMessages.ApplicationRecoveryFailedToRegisterForRestart);
            }
            else if (hr == HResult.InvalidArguments)
            {
                throw new ArgumentException(LocalizedMessages.ApplicationRecoverFailedToRegisterForRestartBadParameters);
            }
        }
		/// <summary>
		/// Registers an application for automatic restart if 
		/// the application 
		/// is terminated by Windows Error Reporting.
		/// </summary>
		/// <param name="settings">An object that specifies
		/// the command line arguments used to restart the 
		/// application, and 
		/// the conditions under which the application should not be 
		/// restarted.</param>
		/// <exception cref="System.ArgumentException">Registration failed due to an invalid parameter.</exception>
		/// <exception cref="System.InvalidOperationException">The attempt to register failed.</exception>
		/// <remarks>A registered application will not be restarted if it executed for less than 60 seconds before terminating.</remarks>
		public static void RegisterForApplicationRestart(RestartSettings settings) {
			// Throw PlatformNotSupportedException if the user is not running Vista or beyond
			CoreHelpers.ThrowIfNotVista();
			if (settings == null) { throw new ArgumentNullException("settings"); }

			HResult hr = AppRestartRecoveryNativeMethods.RegisterApplicationRestart(settings.Command, settings.Restrictions);

			if (hr == HResult.Fail) {
				throw new InvalidOperationException(LocalizedMessages.ApplicationRecoveryFailedToRegisterForRestart);
			} else if (hr == HResult.InvalidArguments) {
				throw new ArgumentException(LocalizedMessages.ApplicationRecoverFailedToRegisterForRestartBadParameters);
			}
		}