Skip to content

Adventures in task scheduling aka How to get your pc to actually awaken on a schedule

September 10, 2009

Whenever you engineer a new system there are always a few tiny things that turn into huge headaches. The most recent one for the gigavision system has been getting the timing sequence for all the components to work correctly.

At the core of the gigavision system is an Asus EEE pc running our custom-built software for shooting the panorama images. I planned to have the PC wake itself from hibernation, run our gigavision software and then re-hibernate until the next time period.  This should be a trivial task and are plenty of places that explain how to do this online.

However, after about 9 hours of pulling my hair out it seems waking from hibernation is not as simple as it might appear. To begin with, it turns out 3rd party software can disable the wake from hibernation feature. If you don’t realize this is going on you get totally unpredictable behavior depending on if the machine you are testing itself happens to be plugged in or not. I tracked it down after I plugged in by hibernating, unplugged machine that wasn’t waking up for the task, and it immediately woke up and worked like it was supposed to.

But that still didn’t fix our problems and I finally found a discussion of a much less well known problem… it turns out that if you use the code that everyone including microsoft says to use to hibernate your XP machine via a batch file (i.e. “%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState”), the task scheduler can’t wake the system from hibernation for some reason. I didn’t explore this extensively other to reproduce it on two different notebooks. If you schedule as task and then hibernate your machine with a bat file running the above code it won’t ever wake. Hibernate via the start menu or the power button and the scheduled task wakes your computer up fine and runs like it should! You’d think it might occur to MS that if people are scripting their machines to sleep, they might be scripting them to wake up too. It ain’t rocket science!

Mercifully, Visual Basic.net provides a simple route to hibernating the machine which doesn’t incur the weird issues we were having, so in the end, all our headaches were solved with a simple line of code:

      Application.SetSuspendState(PowerState.Hibernate, true, true)
Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: