How do I check when the computer is being put to sleep or wakes up?

前端 未结 1 1694
庸人自扰
庸人自扰 2020-12-18 21:12

I want to make my program aware of the computer being put to sleep or waking up from sleep, possibly have an event that is triggered when either of these occur. Is this poss

相关标签:
1条回答
  • 2020-12-18 21:45

    You can subscribe to the SystemEvents.PowerModeChanged event.

    SystemEvents.PowerModeChanged += OnPowerChange;
    
    void OnPowerChange(Object sender, PowerModeChangedEventArgs e) {
      switch ( e.Mode ) {
        case PowerModes.Resume: 
          ...
        case PowerModes.Suspend:
          ...
      }
    }
    
    0 讨论(0)
提交回复
热议问题