views:

110

answers:

1

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?

+5  A: 

You can susbcribe to the SystemEvents.PowerModeChanged event.

SystemEvents.PowerModeChanged += OnPowerChange;

void OnPowerChange(Object sender, PowerModeChangedEventArgs e) {
  switch ( e.Mode ) {
    case PowerModes.Resume: 
      ...
    case PowerModes.Suspend:
      ...
  }
}
JaredPar