/// <summary> /// Starts the countdown with values from UI /// </summary> private void StartCountdown(bool forced = false) { ExceptionHandler.LogEvent("[Menu] Starting countdown..."); // Calculate TimeSpan ExceptionHandler.LogEvent("[Menu] Calculating timespan"); TimeSpan timeSpan = new TimeSpan(Convert.ToInt32(hoursNumericUpDown.Value), Convert.ToInt32(minutesNumericUpDown.Value), Convert.ToInt32(secondsNumericUpDown.Value)); // Show countdown window ExceptionHandler.LogEvent("[Menu] Preparing countdown window..."); using (Countdown countdown = new Countdown { CountdownTimeSpan = timeSpan, Action = actionComboBox.Text, Graceful = gracefulCheckBox.Checked, PreventSystemSleep = preventSleepCheckBox.Checked, UI = !backgroundCheckBox.Checked, Forced = forced, Password = password }) { countdown.Owner = this; ExceptionHandler.LogEvent("[Menu] Opening countdown window..."); countdown.ShowDialog(); ExceptionHandler.LogEvent("[Menu] Exiting"); Application.Exit(); // Exit application after countdown is closed } }
/// <summary> /// Starts the countdown with values from UI /// </summary> private void StartCountdown() { ExceptionHandler.LogEvent("[Menu] Starting countdown..."); // Calculate TimeSpan ExceptionHandler.LogEvent("[Menu] Calculating timespan"); TimeSpan timeSpan; if (countdownModeRadioButton.Checked) { // Calculate TimeSpan for Countdown as it was given in the form timeSpan = new TimeSpan(Convert.ToInt32(hoursNumericUpDown.Value), Convert.ToInt32(minutesNumericUpDown.Value), Convert.ToInt32(secondsNumericUpDown.Value)); } else { // Use form data as a point in time and calculate TimeSpan from now to this point bool today = TodayOrTomorrow(Convert.ToInt32(hoursNumericUpDown.Value), Convert.ToInt32(minutesNumericUpDown.Value), Convert.ToInt32(secondsNumericUpDown.Value)); DateTime target = DateTime.Parse(Convert.ToInt32(hoursNumericUpDown.Value) + ":" + Convert.ToInt32(minutesNumericUpDown.Value) + ":" + Convert.ToInt32(secondsNumericUpDown.Value)); if (!today) { target = target.AddDays(1); } timeSpan = target.Subtract(DateTime.Now); } // Show countdown window ExceptionHandler.LogEvent("[Menu] Preparing countdown window..."); using (Countdown countdown = new Countdown { CountdownTimeSpan = timeSpan, Action = actionComboBox.Text, Graceful = gracefulCheckBox.Checked, PreventSystemSleep = preventSleepCheckBox.Checked, UI = !backgroundCheckBox.Checked, Password = password, UserLaunch = true, Command = command }) { countdown.Owner = this; ExceptionHandler.LogEvent("[Menu] Opening countdown window..."); countdown.ShowDialog(); ExceptionHandler.LogEvent("[Menu] Exiting"); Application.Exit(); // Exit application after countdown is closed } }