Exemple #1
0
        private static void ApplicationRecoverySettings(
            IntPtr processHandle,
            out RecoveryCallback recoveryCallback,
            out RecoveryData parameter,
            out uint pingInterval)
        {
            uint flags = 0;
            uint returnValue;

            returnValue = NativeMethods.GetApplicationRecoveryCallback(
                processHandle,
                out recoveryCallback,
                out parameter,
                out pingInterval,
                out flags);

            if (returnValue == SafeNativeMethods.ResultFalse || recoveryCallback == null)
            {
                throw new InvalidOperationException(
                          "Application is not registered for recovery.");
            }
            if (returnValue == SafeNativeMethods.ResultInvalidArgument)
            {
                throw new ArgumentException(
                          "Failed to get application recovery settings due to bad parameters.");
            }
        }
 /// <summary>
 /// Creates a new instance of this class.
 /// </summary>
 /// <param name="callbackDelegate">The callback method that will be invoked by 
 /// the system before Windows Error Reporting (WER) terminates the 
 /// application.</param>
 /// <param name="theParameter">An optional argument for the callback method. </param>
 /// <param name="thePingInterval">The time interval within which the 
 /// callback method must invoke <see cref="Microsoft.SDK.Samples.VistaBridge.Library.AppRecoveryRestart.ArrManager.ApplicationRecoveryInProgress"/> to 
 /// prevent WER from terminating the application.</param>
 /// <seealso cref="Microsoft.SDK.Samples.VistaBridge.Library.AppRecoveryRestart.ArrManager"/>
 public RecoverySettings(
     RecoveryCallback callbackDelegate,
     RecoveryData theParameter,
     uint thePingInterval)
 {
     this.recoveryCallback = callbackDelegate;
     this.parameter = theParameter;
     this.pingInterval = thePingInterval;
 }
Exemple #3
0
 /// <summary>
 /// Creates a new instance of this class.
 /// </summary>
 /// <param name="callbackDelegate">The callback method that will be invoked by
 /// the system before Windows Error Reporting (WER) terminates the
 /// application.</param>
 /// <param name="theParameter">An optional argument for the callback method. </param>
 /// <param name="thePingInterval">The time interval within which the
 /// callback method must invoke <see cref="Microsoft.SDK.Samples.VistaBridge.Library.AppRecoveryRestart.ArrManager.ApplicationRecoveryInProgress"/> to
 /// prevent WER from terminating the application.</param>
 /// <seealso cref="Microsoft.SDK.Samples.VistaBridge.Library.AppRecoveryRestart.ArrManager"/>
 public RecoverySettings(
     RecoveryCallback callbackDelegate,
     RecoveryData theParameter,
     uint thePingInterval)
 {
     this.recoveryCallback = callbackDelegate;
     this.parameter        = theParameter;
     this.pingInterval     = thePingInterval;
 }
Exemple #4
0
        /// <summary>
        /// Returns the current settings for application recovery.
        /// </summary>
        /// <param name="processHandle">A handle to the application's
        /// process.</param>
        /// <returns>A <see cref="Microsoft.SDK.Samples.VistaBridge.Library.AppRecoveryRestart.RecoverySettings"/> object that specifies
        /// the callback method, an optional parameter to pass
        /// to the callback method and the time interval
        /// within which the callback method
        /// calls the <see cref="Microsoft.SDK.Samples.VistaBridge.Library.AppRecoveryRestart.ArrManager.ApplicationRecoveryInProgress"/> method to indicate
        /// that it is still performing recovery work.</returns>
        /// <exception cref="System.ArgumentException">Cannot get the settings due to an invalid parameter.</exception>
        /// <exception cref="System.InvalidOperationException">The application is not registered for recovery.</exception>
        public static RecoverySettings ApplicationRecoverySettings(
            IntPtr processHandle)
        {
            RecoveryData     parameter = null;
            RecoveryCallback recoveryCallback;
            uint             pingInterval;

            ApplicationRecoverySettings(
                processHandle,
                out recoveryCallback,
                out parameter,
                out pingInterval);

            RecoverySettings settings = new RecoverySettings(
                recoveryCallback, parameter, pingInterval);

            return(settings);
        }
        private static void RegisterForApplicationRecovery(
            RecoveryCallback recoveryCallback,
            RecoveryData parameter,
            uint pingInterval)
        {
            uint returnValue = NativeMethods.RegisterApplicationRecoveryCallback(
                recoveryCallback,
                parameter,
                pingInterval,
                (uint)0);

            if (returnValue == SafeNativeMethods.ResultFalse)
            {
                throw new Win32Exception(
                    "Application failed to register for recovery.");
            }
            if (returnValue == SafeNativeMethods.ResultInvalidArgument)
            {
                throw new ArgumentException(
                    "Application was not registered for recovery due to bad parameters.");
            }
        }
Exemple #6
0
        private static void RegisterForApplicationRecovery(
            RecoveryCallback recoveryCallback,
            RecoveryData parameter,
            uint pingInterval)
        {
            uint returnValue = NativeMethods.RegisterApplicationRecoveryCallback(
                recoveryCallback,
                parameter,
                pingInterval,
                (uint)0);

            if (returnValue == SafeNativeMethods.ResultFalse)
            {
                throw new Win32Exception(
                          "Application failed to register for recovery.");
            }
            if (returnValue == SafeNativeMethods.ResultInvalidArgument)
            {
                throw new ArgumentException(
                          "Application was not registered for recovery due to bad parameters.");
            }
        }
        private static void ApplicationRecoverySettings(
            IntPtr processHandle,
            out RecoveryCallback recoveryCallback,
            out RecoveryData parameter,
            out uint pingInterval)
        {
            uint flags = 0;
            uint returnValue;

            returnValue = NativeMethods.GetApplicationRecoveryCallback(
            processHandle,
            out recoveryCallback,
            out parameter,
            out pingInterval,
            out flags);

            if (returnValue == SafeNativeMethods.ResultFalse || recoveryCallback == null)
            {
                throw new InvalidOperationException(
                    "Application is not registered for recovery.");
            }
            if (returnValue == SafeNativeMethods.ResultInvalidArgument)
            {
                throw new ArgumentException(
                    "Failed to get application recovery settings due to bad parameters.");
            }
        }
Exemple #8
0
 internal static extern uint RegisterApplicationRecoveryCallback(
     RecoveryCallback recoveryCallback,
     RecoveryData parameter,
     uint pingInterval,
     uint flags); // Unused.
Exemple #9
0
 internal static extern uint GetApplicationRecoveryCallback(
     IntPtr processHandle,
     out RecoveryCallback recoveryCallback,
     out RecoveryData parameter,
     out uint pingInterval,
     out uint flags);
Exemple #10
0
        // This method is invoked by WER. 
        private static int RecoveryProcedure(RecoveryData parameter)
        {
            Console.WriteLine("Recovery in progress for {0}",
                parameter.CurrentUser);

            // Do recovery work here.
            for (int i = 0; i < 4; i++)
            {
                // Signal to WER that the recovery
                // is still in progress.
                PingSystem();
                // Simulate long running recovery.
                System.Threading.Thread.Sleep(3000);
            }
            // Indicate that recovery work is done.
            Console.WriteLine("Application shutting down...");
            ArrManager.ApplicationRecoveryFinished(true);
            return 0;
        }