How can I know when Windows is going into/out of sleep or Hibernate mode?
Microsoft.Win32.SystemEvents.PowerModeChanged
event will give you this information. This event is available in all variants of the .NET framework released by Microsoft so far.
In .NET, use the PowerModeChanged event. In Win32, use the WM_POWERBROADCAST message.