Is there any way (short of manually doing so in the Windows settings each time I run it) to make a running WPF application prevent Windows from going to sleep/hibernating/etc. The application is just running a continuous loop every 10 seconds in a BackgroundWorker. I noticed when my machine auto-slept, it stopped my BackgroundWorker, and I'd like to keep it running indefinitely.
If its not possible purely in WPF, are there other ways?
You can use the SetThreadExecutionState API function. More information is given here
However, don't do that if you don't really have to, and certainly don't do that before getting the user's explicit consent. Your users will be pissed off when they realize their laptops die while your program is running. So warn them properly so they're not pissed off.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With