How to find out the reason why a scheduled task hang?

1

I have scheduled quite a number of tasks in my Windows 7, doing a variety of cron jobs on my machines.

I am perfectly sure that these tasks, when run on their own, won't hang. But the problem is that, when I run them daily, over the course of several days and weeks and months, occasionally some of them will hang.

So I am forced to kill the hanged task and rerun it--- and now it can run successfully!

I want to fix this problem once and for all, and for that, I need to know why a scheduled task will hang, even when I run it separately, it won't.

Anyway for me to find out the reason?

Graviton

Posted 2014-08-22T07:55:48.243

Reputation: 5 006

2EventViewer may shed some light – Dave – 2014-08-22T08:20:19.753

@Dave, would you like to convert your comment into an answer? It's quite useful – Graviton – 2014-08-22T09:29:35.090

What are the jobs doing (don't need details, just an overview). Are you sharing resources between each job for example or changing state? – Dave – 2014-08-22T10:20:37.737

@Dave, nope, no sharing of resources. Plus, all the tasks run sequently, no overlap of them – Graviton – 2014-08-22T10:49:45.363

I wonder if it's a resource issue then, like out of memory or similar (may be due to another unrelated task being executed at the same time) – Dave – 2014-08-22T10:57:44.120

@Dave, don't think so, because when I kill the schedule task, and rerun it, it still runs – Graviton – 2014-08-22T10:58:43.397

OK, was thinking it was a memory leak or similar – Dave – 2014-08-22T10:59:22.843

Answers

1

When you check your tasks, it will show you the last run status at the far right. This usually shows you why the task fails. It is possible that the task hung during execution even though it was processed normally, so the task keeps on running and thus doesn't technically fail.

As a result, the next time the task is supposed to run, it doesn't run because a previous task was still running. So the error becomes: Previous task still runs.

I usually counteract this by setting that the maximum execution time is less than when the next task is scheduled to run. If I know the task is only supposed to run a few minutes max, I usually set the force quit to 5 minutes and enable restarting the tasks a few times. This will ensure that if the task for whatever reason doesn't run right, it will abort and do it again. If taskscheduler gets the OK that the task was run right, it will not retry the task another time.

LPChip

Posted 2014-08-22T07:55:48.243

Reputation: 42 190

2

I would suggest starting off with EventViewer as if it's a crash, it should be logged.

You could also add some logging functionality to your program to see which module/task it's failing on.

Deleted as realised LPChip wrote similar: Also, as a total work around, in task scheudler, you can force it to quit if it takes more than 72 hours to complete (I think this is default). If you know the task should take only a few minutes to complete, than change that value to 30 minutes (give yourself lots of head room). It won't help you solve it, but if it's something you have to keep going, it may suffice while you debug further.

Dave

Posted 2014-08-22T07:55:48.243

Reputation: 24 199