Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event to detect System wake up from sleep in C#

Tags:

c#

windows

events

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?

like image 769
Pankaj Avatar asked Aug 13 '13 10:08

Pankaj


People also ask

How do I find out why my computer wakes up?

In the sidebar, head to Windows Logs > System, then click Filter Current Log on the right side of the window. In Windows 11, it's called Create Custom View. Choose Power-Troubleshooter from the Event Sources drop-down menu and click OK to see all the times your computer woke up recently and what caused them.

What is wakeup event?

A network wake-up event is an external event that causes a network adapter to wake the system. A network adapter wakes the system by asserting a bus-specific wake-up signal that eventually results in the system making a transition from a sleeping state to the working state.

What wakes my PC from sleep?

There is a good chance that your PC's Network Adapter is waking it. This is a Power & Sleep issue. You may disable this ability by locating your PC's Network Adapter in Device Manager and opening the Properties window.


1 Answers

SystemEvents.PowerModeChanged += OnPowerChange;  private void OnPowerChange(object s, PowerModeChangedEventArgs e)  {     switch ( e.Mode )      {         case PowerModes.Resume:          break;         case PowerModes.Suspend:         break;     } } 

You should probably read this: http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.powermodechanged.aspx

like image 54
Marcus Avatar answered Oct 20 '22 19:10

Marcus