2

How can my program do something when the computer is going to "sleep", and do something when it wakes up? My program uses the "IPv4InterfaceStatistics" class to save ..send and receive.. Bytes and it saves unreal values when the computer wakes up from sleeping. Thanks for you help!

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
as206em
  • 21
  • 1
  • See this [possible duplicate](http://stackoverflow.com/questions/1562474/how-do-i-check-when-the-computer-is-being-put-to-sleep-or-wakes-up). In general you should specify an operating system when asking about sleep mode. Even if the reader assumes "Windows", which version are you targeting? – hardmath Apr 30 '11 at 11:11
  • Can you add the OS you are using? This question plausably applies to Linux, Solaris, Windows, OSX, Android and iPhoneOS ( These are all platforms where System.Net.NetworkInformation.IPv4InterfaceStatistics is availible from C# ) – IanNorton Apr 30 '11 at 11:14

1 Answers1

2

Take a look at the RegisterPowerSettingNotification Win API Method. It will allow your application to receive WM_POWERBROADCAST which you handle via your WndProc method.

Here's the pinvoke.net article to help you add it to your application. http://www.pinvoke.net/default.aspx/user32/registerpowersettingnotification.html

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97