First time poster, be gentle 😉
I’m writing an audio app (in C++) which runs as a Windows service, uses WASAPI to take samples from the line in jack, and does some processing on it.
Something I’ve noticed is that when my app is ‘recording’, Windows won’t automatically suspend or hibernate.
I’ve registered for power event notifications and, if I push the suspend button myself, my service gets the appropriate power events and handles them ok. If I leave the system to suspend on its own, the power events are never received.
If I remove the bits of code where I reference WASAPI, the power events are received as normal on both manual and automatic suspend. So it seems like there’s something about using WASAPI that tells Windows to ignore the automatic suspend timer.
Can anyone help explain this behavior, and is there anything I can do to stop it? I don’t want my app to be one of those which misbehaves and prevents systems from suspending..
Many thanks to Larry for confirming this behaviour is by design and not me doing something silly.
To work around this issue I used the Win32
CallNtPowerInformation()API to retrieve the system idle timer:The
spi.TimeRemainingmember counts down (in seconds) from the time specified by the user in Control Panel e.g. ‘System standby after 1 hour’, and gets reset whenever CPU usage (as a percentage) rises abovespi.MaxIdlenessAllowed.If
spi.TimeRemainingever reaches zero, the system should have gone to sleep, so I close all my WASAPI handles and let it do so.