Pankaj Pankaj - 1 year ago 229
C# Question

Event to detect System wake up from sleep in C#

I need to detect the system power state mode. To be precise, I need an event which fires up when windows 7 wakes up from sleep. I am already using:

SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

But the problem with this event is that it is raised up four times: possibly when computer goes into sleep mode and after computer wakes up. I want an event which is raised at computer wake up only. Is there any event for this?

Answer Source
SystemEvents.PowerModeChanged += OnPowerChange;

private void OnPowerChange(object s, PowerModeChangedEventArgs e) 
    switch ( e.Mode ) 
        case PowerModes.Resume: 
        case PowerModes.Suspend:

You should probably read this:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download