Ejemplo n.º 1
0
        private static uint RecoveryHandler(IntPtr parameter)
        {
            bool cancelled = false;

            ApplicationRecoveryInProgress(out cancelled);
            if (cancelled)
            {
                return(0);
            }

            GCHandle         handle   = GCHandle.FromIntPtr(parameter);
            RecoverySettings settings = (RecoverySettings)handle.Target;

            settings.Callback?.Invoke(settings.State);
            handle.Free();

            return(0);
        }
Ejemplo n.º 2
0
        public static void RegisterApplicationRecovery(RecoverySettings settings)
        {
            if (!IsPlatformSupported)
            {
                throw new PlatformNotSupportedException("Requires Windows Vista or later");
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            GCHandle handle = GCHandle.Alloc(settings);
            int      hr     = NativeMethods.RegisterApplicationRecoveryCallback(NativeMethods.InternalRecoveryHandler,
                                                                                GCHandle.ToIntPtr(handle), (uint)Math.Round(settings.PingInterval.TotalMilliseconds), 0);

            if (hr != 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
        }