Пример #1
0
 public void SetTimer(int?secondsToShutdown, Controls.ProgressBarWithText progressBar, ShutdownTimerPicker.ShutdownTimerAction action, PersistentSettings.StartObjects.StartObjectsManager startObjects)
 {
     if (!secondsToShutdown.HasValue)
     {
         shutdownTimer?.Cancel();
         return;
     }
     shutdownTimer = new ShutdownTimer(secondsToShutdown.Value, progressBar, this, action, startObjects);
 }
Пример #2
0
        public ShutdownTimer(int secondsToShutdown, Controls.ProgressBarWithText progressBar, App app, ShutdownTimerPicker.ShutdownTimerAction action, PersistentSettings.StartObjects.StartObjectsManager startObjects)
        {
            AutoShutdownCancelled = false;
            timerSecondsRemaining = secondsToShutdown;
            _progresBar           = progressBar;
            _app = app;
            _progresBar.Bar.Maximum = secondsToShutdown;
            _progresBar.Bar.Value   = secondsToShutdown;
            switch (action)
            {
            case ShutdownTimerPicker.ShutdownTimerAction.Quit:
                shutdownAction = () => _app.Shutdown();
                break;

            case ShutdownTimerPicker.ShutdownTimerAction.LaunchAndQuit:
                shutdownAction = () => { startObjects.LaunchAllInCurrentProfile().Wait(); _app.Shutdown(); };
                break;

            default:
                break;
            }
            _timer = new System.Windows.Threading.DispatcherTimer
            {
                Interval = System.TimeSpan.FromSeconds(1)
            };
            _timer.Tick += Timer_Tick;
            _timer.Start();
        }