|
Prevent Sleep During Scheduled Tasks
I've been trying to cut back on the amount of power we use at home. This is partly virtuous, but mainly because I've started tracking power consumption vs. generation for our solar panels (even though it's December I want to try and have a day of net generation, you can see my progress on this chart).
I bought a couple of smart strips and now have both main computers set to switch all their peripherals off when they go to sleep. This goes from 250-300 watts to 1-2 watts - very cool.
There was a problem though. I run all sorts of overnight processing - backing up databases, processing web stats, updating the webcam list for WebCamSaver - and the computer kept going to sleep in the middle of it.
Task scheduler lets you wake your computer to run a task, but there doesn't seem to be an option to stop it sleeping until the task has finished. I hunted around for a while, but it seemed like one of those times when it's just faster to write something.
Nosleep (source) is a command line tool that disables sleep or hibernate, runs a batch file or program and then enables sleep or hibernate again. It will run on any recent version of Windows - I use it from task scheduler to launch my monster batch file of overnight tasks.
It's a simple little app - it just calls SetThreadExecutionState() before and after launching the target batch file. The trick with SetThreadExecutionState is that the new state doesn't take the first time you call the function. Calling it twice has the desired effect. Labels: Tools
Posted by Rob on 12/07/2008, 4 comments.
(Bookmark & Share)
Comments
Subscribe to comments on this post.
Thanks for the no sleep script. Very helpful and appreciated!
Rob, Thanks for this utility and making the source code available, too. I think it is precisely what I've been looking for.
wait - what do you mean you run it before and after the schedule task or that you need to call it twice?
Also, how do you reenable sleep mode after the tasks finish?
TIA.
TIA: it's a wrapper, nosleep runs the task and then stays resident until the task completes.
The way I use it is to put the task (or tasks) in a batch file and then call the batch file from nosleep:
nosleep.exe mytasks.bat
The batch file is the parameter to nosleep. Hope this helps, if not email me.
Post a Comment
Links
|