I am trying to implement a windows service that sends a message when the system goes into standby mode (sleep). My test machine OS is a Windows 8 pro. The service has CanHandlePowerEvents=true and OnPowerEvent overwritten and it indeed receives power events.
The issue I encountered is: OnPowerEvent never receives QuerySuspend message. It does however receive Suspend message before computer goes into suspend but the OS doesn't wait for OnPowerEvent method to complete, it just goes into suspend mode regardless, then after resume, the execution of the OnPowerEvent method continues.
Thing is sending a message over internet may take 1-2 seconds so it always ends up being sent after the computer resumes and never before going into suspend mode as it is supposed to work.
Any ideeas on how to solve this, anyone?