Alex Rivera | Logout

Prevent windows from going into sleep when my program is running?

Asked 2009-03-10T07:41:42.497
43

I have to stop windows from going into sleep when my program is running.

And I don't only want to prevent the sleep-timer, I also want to cancel the sleep-event if I press the sleep-button or in any other way actively tell the computer to sleep. Therefore SetThreadExecutionState is not enough.

Or...I don't actually have to prevent the sleep completely, only delay it 5-10sec to allow my program to finish a task.

(I know that this is bad program behavior but it's only for personal use.)

Edit
Report

1 Answer

10

Using PowerCreateRequest, PowerSetRequest, and PowerClearRequest functions is the preferred method. Details and sample code (C/C#) are inside http://msdn.microsoft.com/en-us/library/windows/hardware/gg463205.aspx

answered 2013-04-18T15:03:35.627

Your Answer