Scheduler wakes, doesn't wait for task to end, then goes back to s

G

Guest

I have a task to run an executable. I have it set to run whether the user is
logged in or not, run with the highest privileges, wake the computer to run
this task, stop the task if it runs longer than 8 hours. It runs at 1am. The
task wakes the computer up at 1am fine, starts the executable, then puts the
computer back to sleep without waiting for the executable (a VS2005 SP1 C#
program I created) to complete. When I wake the computer in the morning, the
executable resumes.

What is up with this? Why can't the task scheduler wait until the task it
spawned finishes? My vista installation was an upgrade from XP Pro. But I
created the task (several times) from scratch in Vista. I also recompiled the
executable in Vista.

I have also tried the task in both "Windows Server 2003, Windows XP, or
Windows 2000" mode and in "Windows Vista" mode.

This is a huuuuuge step backward for me. I would appreciate any help anyone
can offer for this.
 
C

cquirke (MVP Windows shell/user)

On Sat, 17 Mar 2007 07:10:10 -0700, Pete Furtado <Pete
I have a task to run an executable. I have it set to run whether the user is
logged in or not, run with the highest privileges, wake the computer to run
this task, stop the task if it runs longer than 8 hours. It runs at 1am. The
task wakes the computer up at 1am fine, starts the executable, then puts the
computer back to sleep without waiting for the executable (a VS2005 SP1 C#
program I created) to complete. When I wake the computer in the morning, the
executable resumes.
What is up with this? Why can't the task scheduler wait until the task it
spawned finishes? My vista installation was an upgrade from XP Pro. But I
created the task (several times) from scratch in Vista. I also recompiled the
executable in Vista.

Is the PC set to "suspend" after some time of inactivity?

If so, turn that off - as that may cut in just because there's no
keyboard or mouse activity going on.

Are there any settings within the Task's properties to control this
sort of behavior?


--------------- ---- --- -- - - - -
Saws are too hard to use.
Be easier to use!
 
G

Guest

Thanks for the reply.

It is set to go into standby after 2 hours. But it seems to go right back to
sleep after spawning the task. My executable writes informational messages to
the event log and I see it writing messages for about 30 seconds to a minute,
then nothing. I'm assuming that is when the machine goes back into standby.

I will double-check this tonight, though, and change the power scheme to
just leave the machine on all night and see what happens.

I can't find any other settings in the task's properties other than what I
stated in my original post. If there's some "hidden" ones, I'm dying to find
out.

I'll update this thread tomorrow with the results.

Thanks again.
 
A

Adam

I will double-check this tonight, though, and change the power scheme to
just leave the machine on all night and see what happens.

I can't find any other settings in the task's properties other than what I
stated in my original post. If there's some "hidden" ones, I'm dying to
find
out.

Hi Pete,

Did you find a sollution to this? I'm having the same problem, although
only with a batch file which backs up some files. It normally takes around
15 to 20 minutes to run, but I can see from the event log that although the
Vista machine wakes up fine, it goes back into standby after about 7 or 8
minutes. My power settings tell the PC to go into standby after 1 hour.

I can't see a "keep machine awake while running task" option in the task
scheduler, which is exactly what I want.

A.
 
G

Guest

STILL NO LUCK!!!!

This is just unbelievable to me! You would think that with all the talk
about power saving and global warming, the LEAST that Microsoft could do
would be to make a task scheduler that actually allows you to leave your
computer in standby mode and only wake up to run a job or two and then go
back to sleep. They had it right in XP pro, before I upgraded my machine to
Visita this stuff worked flawlessly in XP Pro.

Unless I find an answer to this, I won't be upgrading my Media Center 2005
box to Vista, because I have that box in standby 20 hours a day and waking
up and recording, etc.

Okay, now that my ranting is done, I just say that if I find anything out,
I'll post it here. And if anyone has an answer to this, please let us know!

Thanks. Pete
 
A

Adds

Humm... It's certainly annoying.

I haven't been able to find out anything about it, dispite spending several
hours on Google. All I've found so far is

http://technet.microsoft.com/en-us/windowsvista/aa906020.aspx

Which says "Task Scheduler wakes the machine to run the tasks and allows it
to return to standby or hibernation when the task is complete, saving energy
while still ensuring that critical tasks run on time."

And our systems obviosuly aren't working like that - They're returning to
standby mode before the task completes.

I'll keep looking, and will post back here if I find anything.

A.
 
A

Adds

Adds said:
Humm... It's certainly annoying.

I think I might have found away around this, although not ideal.

In my batch file, I'm running powercfg first to set the PC into "High
Performance" mode (powercfg /? will give the options). I then set it back
to my normal power mode after the batch file has complete.

I have to admit that I haven't given it long enough to test properly, but it
appears to work.

Not ideal I know, but at least it might be a work around.

A.
 
G

Guest

Adds said:
I think I might have found away around this, although not ideal.

In my batch file, I'm running powercfg first to set the PC into "High
Performance" mode (powercfg /? will give the options). I then set it back
to my normal power mode after the batch file has complete.

I have to admit that I haven't given it long enough to test properly, but it
appears to work.

Not ideal I know, but at least it might be a work around.

A.

Interesting idea. I got so disgusted with this problem that I gave up for a
while.

Anyway, how has it worked for you? I will try this myself in the next couple
of days. Thanks!
Pete
 
G

Guest

I've got two Vista machines doing this as well. Using a batch file to switch
to high performance mode where sleep is set to "never" before the task runs
doesn't fix the problem. Both machines drop back to sleep within a minute or
two of task start regardless of power mode. I originally ran across this
problem with defrag and thought it might have to do with the fact that defrag
does low-priority (background) I/O, but I've reproduced the problem with
several different disk I/O intensive tasks that use normal priority I/O so
that's not it (and just in case anybody is wondering: removing the -i switch
on defrag has no affect either).

Looks like a Vista power management bug to me. Windows has certainly had
it's fair share of these over the years. Lets hope the bug gets fixed in SP1
or (hopefully) sooner in an update.

Clayton Gautier
 
G

Guest

In case anyone still cares about this issue, I've come up with a work-around.
It involves the Win32 API function SetThreadExecutionState (kernel32.dll).
You can find the details on the web, but basically, Windows can be forced to
stay awake while a process runs by sandwiching the process between two
SetThreadExecutionState calls (with different arguments for the calls). The
sandwiching can be implemented in a variety of ways - I chose to create an
executable, named StayAwakeExec in VB 2005 Express Edition (free) that does
the following:

1) makes the first call to SetThreadExecutionState to block sleep
2) spawns an executable passed in as a command line argument
3) makes the second call to SetThreadExecutionState to allow sleep after
the spawned executable exits

Note that the "after the spawned executable exits" part of Step 3 is
implemented by calling Process.WaitForExit() for the spawned executable.

I've successfully used StayAwakeExec to spawn defrag.exe with a task that
wakes the computer at 1AM. The computer now wakes, runs defrag to
completion, and then goes back to sleep immediately after the defrag finishes
(as verified by the system log file).

I was hoping that the latest Vista performance and reliability patches
(KB938194 and KB938979) would fix the bug, design flaw - whatever you want to
call it - that made this workaround necessary, but alas, twas not so. I
tested both my systems after installing these patches and Vista still falls
asleep almost exactly 2 minutes after a scheduled task wakes the computer
regardless of whether the task is done. My expectation (and I'm pretty sure
most people would agree) is if you check the "Wake the computer to run this
task" checkbox on the Conditions tab in Task Schedular, Windows should stay
awake until the task is complete. It should be a simple matter for an MS
developer to add to the task schedular service the sandwiching calls to
SetThreadExecutionState to prevent sleep if "Wake the computer to run this
task" is checked. Hopefully SP1 will have this fix.
 
G

Guest

Thanks for the tip, clayga! That works most of the time on my pc. I did
basically the same thing, i have a separate executable calling
SetThreadExecutionState, and then I just call that first from vbscript, do
anything else I need to do via vbscript, then kill that task and exit the
script.

Sorry for the late reply. I couldn't log into this site for a while for some
reason.

I still have more problems with this stupid Vista task scheduler. Sometimes
tasks just don't run. Yes, yes, i know all the options to wake computer to
run this task, and run whether user is logged on or not. They just did a
really, really bad implementation of the task scheduler in Vista. I hope they
fix it one of these days.

Thanks again!

Pete Furtado
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top