Exemplo n.º 1
0
    private void LifetimeOnShutdownRequested(object?sender, ShutdownRequestedEventArgs e)
    {
        // Shutdown prevention will only work if you directly run the executable.
        e.Cancel = !ApplicationViewModel.CanShutdown();

        Logger.LogDebug($"Cancellation of the shutdown set to: {e.Cancel}.");

        _stateMachine.Fire(e.Cancel ? Trigger.ShutdownPrevented : Trigger.ShutdownRequested);
    }
        public int TryShutdown()
        {
            if (ShutdownRequested is null)
            {
                return(1);
            }
            var e = new ShutdownRequestedEventArgs();

            ShutdownRequested(this, e);
            return((!e.Cancel).AsComBool());
        }
Exemplo n.º 3
0
        private void RemoteService_ShutdownRequested(object sender, ShutdownRequestedEventArgs e)
        {
            if ((DateTime.Now - _lastShutdownRequest).TotalSeconds < 30)
            {
                return;
            }

            _exit = true;
            WindowsHelpers.Shutdown();
            Application.Exit();
        }
Exemplo n.º 4
0
        private bool DoShutdown(ShutdownRequestedEventArgs e, bool force = false, int exitCode = 0)
        {
            if (!force)
            {
                ShutdownRequested?.Invoke(this, e);

                if (e.Cancel)
                {
                    return(false);
                }

                if (_isShuttingDown)
                {
                    throw new InvalidOperationException("Application is already shutting down.");
                }
            }

            _exitCode       = exitCode;
            _isShuttingDown = true;

            try
            {
                // When an OS shutdown request is received, try to close all non-owned windows. Windows can cancel
                // shutdown by setting e.Cancel = true in the Closing event. Owned windows will be shutdown by their
                // owners.
                foreach (var w in Windows)
                {
                    if (w.Owner is null)
                    {
                        w.Close();
                    }
                }

                if (!force && Windows.Count > 0)
                {
                    e.Cancel = true;
                    return(false);
                }

                var args = new ControlledApplicationLifetimeExitEventArgs(exitCode);
                Exit?.Invoke(this, args);
                _exitCode = args.ApplicationExitCode;
            }
            finally
            {
                _cts?.Cancel();
                _cts            = null;
                _isShuttingDown = false;
            }

            return(true);
        }
        private void ActualInteractHandler(IntPtr smcConn)
        {
            var e = new ShutdownRequestedEventArgs();

            if (_platform.Options?.EnableSessionManagement ?? false)
            {
                ShutdownRequested?.Invoke(this, e);
            }

            SMLib.SmcInteractDone(smcConn, e.Cancel);

            if (e.Cancel)
            {
                return;
            }

            _saveYourselfPhase = false;

            SMLib.SmcSaveYourselfDone(smcConn, true);
        }
        private void OnShutdownRequested(object sender, ShutdownRequestedEventArgs e)
        {
            ShutdownRequested?.Invoke(this, e);

            if (e.Cancel)
            {
                return;
            }

            // When an OS shutdown request is received, try to close all non-owned windows. Windows can cancel
            // shutdown by setting e.Cancel = true in the Closing event. Owned windows will be shutdown by their
            // owners.
            foreach (var w in Windows)
            {
                if (w.Owner is null)
                {
                    w.Close();
                }
            }
            if (Windows.Count > 0)
            {
                e.Cancel = true;
            }
        }
Exemplo n.º 7
0
 private static void BotMainOnShutdownRequested(object sender, ShutdownRequestedEventArgs args)
 => GetModules().ForEach(m => m.ShutDown());
Exemplo n.º 8
0
 private void OnShutdownRequested(object?sender, ShutdownRequestedEventArgs e) => DoShutdown(e);
Exemplo n.º 9
0
 private void HostContext_ShutdownRequested(object sender, ShutdownRequestedEventArgs e)
 {
     Log.Info(string.Format("Server is shut down by {0} for the following reason: {1}", sender, e.Reason));
     Environment.Exit(-1);
 }