开发者

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

开发者 https://www.devze.com 2022-12-08 05:08 出处:网络
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 possible?开发者_JS百科You can s

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 possible?开发者_JS百科


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

精彩评论

暂无评论...
验证码 换一张
取 消