1.

Solve : Scheduled Task That Cannot Hang?

Answer»

Would appreciate some help here. Is it possible to create a DOS Batch script that runs as a Scheduled Task (and executes Excel and ACCESS macros) so that it always exits; i.e., can never get hung? I understand that setting the scheduled task parameter that tells it to end if running longer than x hours doesn't always work. Thanks.Quote from: sumdumgai on January 25, 2011, 01:58:45 PM

I understand that setting the scheduled task parameter that tells it to end if running longer than x hours doesn't always work. Thanks.

First I've heard of this. Have you tested this out?

Both Access and Excel can execute macros when opened. Access at one time used AutoExec and Excel used Auto_Open. Check your help files specific to your versions.

The batch file does not actually execute the macros. You must open Access and Excel via the batch file, and let each application execute the starting macro.

Good luck.

Yes, I've tested this. Even when this parameter is set, if Excel (or Access) is running a macro and for instance if an error occurs that requires a user acknowledgement (like an 'OK
'), then the task remains open (and hung). You'd need the process PID or some other identifier to kill the task.If the macro throws an error, the application goes into a wait state and execution clock stops waiting for your response. VBA supports variations of the on error instruction which allows you to programmatically decide what to do when an error is thrown. I suspect the default action is to put up a window with the error message and line number.

By setting up an on error routine, you can override the default and perhaps completely ignore the error, or even shutdown the macro without halting. This link has more information.

Good luck. Quick resolution to prevent that would be an On Error Resume Next at the top of each macro routine; (and removal of any existing "On Error GOTO 0")When I saw the title I was reminded of something. Isn't asking for a program that "cannot hang" just what Alan Turing proved in 1936 couldn't be done? That is, that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist.
Quote from: Salmon TROUT on February 02, 2011, 01:48:37 PM
When I saw the title I was reminded of something. Isn't asking for a program that "cannot hang" just what Alan Turing proved in 1936 couldn't be done? That is, that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist.

the proof was more that it was impossible, by analyzing the code of a program, to determine wether that program "halts" and in what cases it does so. (The specific source where I read this I cannot recall- but it presented most of it's material using Pascal, and the idea was expressed by presenting pascal programs that had "halt" instructions execute in certain CONDITIONS; while it's possible for a program to determine wether another program "halted" when it was merely a "halt" instruction, the problem became INTRACTABLE as the cyclomatic complexity rose. I can't remember very much about the specifics of that particular chapter.



Of course in this case, the "hang" is only a hang in the context of a scheduled task, since it is asking for user-input.



Discussion

No Comment Found