private void Button_Click(object sender, RoutedEventArgs e)
        {
            SetButton.IsEnabled = false;

            if (ModeSelection.SelectedIndex == 0) // hibernate
            {
                mode = StandbyMode.Hibernate;
            }
            else if (ModeSelection.SelectedIndex == 1) // sleep
            {
                mode = StandbyMode.Sleep;
            }

            try
            {
                int mins = Convert.ToInt32(minutes.Text);
                Set(mins);
            }
            catch
            {
                SetButton.IsEnabled = true;
                System.Windows.Forms.MessageBox.Show("Please enter an integer number.");
            }
        }
Пример #2
0
 /// <summary>
 /// Sets thread execution state to allow / prevent standby (always must be called by one and the same thread)
 /// </summary>
 /// <param name="awayModeRequired">Enable/disable away mode</param>
 public static void SetStandbyMode(StandbyMode standbyMode)
 {
   switch (standbyMode)
   {
     case StandbyMode.StandbyAllowed:
       SetThreadExecutionState(ExecutionState.ES_CONTINUOUS);
       break;
     case StandbyMode.StandbyPrevented:
       SetThreadExecutionState(ExecutionState.ES_SYSTEM_REQUIRED | ExecutionState.ES_CONTINUOUS);
       break;
     case StandbyMode.AwayModeRequested:
       if (Environment.OSVersion.Version.Major >= 6)
         SetThreadExecutionState(ExecutionState.ES_SYSTEM_REQUIRED | ExecutionState.ES_AWAYMODE_REQUIRED | ExecutionState.ES_CONTINUOUS);
       else
         SetThreadExecutionState(ExecutionState.ES_SYSTEM_REQUIRED | ExecutionState.ES_CONTINUOUS);
       break;
   }
 }