/// <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(); HRESULT hr = AppRestartRecoveryNativeMethods.RegisterApplicationRestart(settings.Command, settings.Restrictions); if (hr == HRESULT.E_FAIL) { throw new InvalidOperationException("Application failed to registered for restart."); } if (hr == HRESULT.E_INVALIDARG) { throw new ArgumentException("Failed to register application for restart due to bad parameters."); } }
/// <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); } }
private void RegisterApplicationRecoveryAndRestart() { if (CoreHelpers.RunningOnVista) { // register for Application Restart and Recovery RestartSettings restartSettings = new RestartSettings(string.Empty, RestartRestrictions.None); ApplicationRestartRecoveryManager.RegisterForApplicationRestart(restartSettings); RecoverySettings recoverySettings = new RecoverySettings(new RecoveryData(PerformRecovery, null), c_keepAliveInterval); ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(recoverySettings); } }
private void RegisterForRestart() { var settings = new RestartSettings("/restart", RestartRestrictions.None); ApplicationRestartRecoveryManager.RegisterForApplicationRestart(settings); AppLogger.Log.Info("Restart Registered"); }
/// <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(); HRESULT hr = AppRestartRecoveryNativeMethods.RegisterApplicationRestart(settings.Command, settings.Restrictions); if (hr == HRESULT.E_FAIL) throw new InvalidOperationException("Application failed to registered for restart."); if (hr == HRESULT.E_INVALIDARG) throw new ArgumentException("Failed to register application for restart due to bad parameters."); }
/// <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) { if (settings == null) { throw new ArgumentNullException(nameof(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); } }