15

When I schedule a task in Windows Task Scheduler, I can set "stop the task if it runs longer than" inside task trigger or inside Settings tab.

If I set it inside the trigger it does not automatically populate into Settings, so I think it's different, but what is the difference and which one is better to use?

3
  • 2
    I believe the shorter duration will supersede the longer one.
    – sajawikio
    Nov 16, 2012 at 19:29
  • 1
    Also let's say you make two triggers that say "run one time" one on Tuesday one one Wednesday. If on Tuesday you stop task if run longer than one day, and Wednesday you stop task if run longer than two days, then they will be different. Now suppose on settings tab it says stop if run after 0.5 days, probably that one will supersede
    – sajawikio
    Nov 16, 2012 at 19:32
  • Or what if it's backwards - it could be that the "Settings" one applies unless the more specific one in the "Triggers" is specified and if so that one only applies and not the "Settings" one? - test it out and let me know which is it.
    – sajawikio
    Nov 16, 2012 at 19:32

2 Answers 2

9

I think @sajawikio has it right - the per-trigger "Stop task" option allows you to set multiple triggers which each have their own maximum runtime allowance, where the option on the Settings tab globally applies to all instances of the task.

Example: On one task, I have multiple triggers set. One is to run every Monday at midnight, the other is to run every Thursday at midnight. There's two ways (there's really more, but we're only using the "stop the task..." option here) I could set up the task so that there's never an overlap.

  1. I could set the whole task (under the Settings tab) to have a maximum run-time of 3 days. This prevents task overlapping in the simplest way.

  2. I could set the maximum run-times separately (in the Trigger dialog) for each task. The Monday task would be set to 3 days, and the Thursday task would be set to 4. This gives the Thursday task an extra day to run (should it be needed) while still preventing overlaps.

What would happen if this option is set in both the Triggers screen and the Settings tab? This would require some testing, but there's three possibilities:

  1. Per-trigger options override the global option entirely.
  2. A global option overrides the per-trigger options entirely.
  3. The shortest duration set for the current task wins.

I checked the Help file, and didn't see any clarification on this. To make your tasks perform in a reliable and predictable manner, I suggest you choose one method or the other - never use both together.

1
  • In important distinction I have found is around indefinitely recurring tasks. If the setting in the Trigger, and the task is killed, recurrence will stop until the next scheduled 'daily' start time. Therefore for daily recurring tasks, don't use the Trigger level setting but rather the Task level one. Apr 7 at 19:03
0

thanks for @Iszi 's answer. I tested these two "ExecutionTimeLimit" options on my PC and get such conclusion. My PC's operating system is Windows 10 Professional.

From MSDN document, we can see these options are in some COM interfaces, these interface's implements requires desktop Windows version newer than or equal to Windows Vista.

The conclusion is as below (the timespans are in minutes):

+----------------------------+---------------------------------+-----------------+
| Trigger.ExecutionTimeLimit | TaskSettings.ExecutionTimeLimit | Realistic Limit |
+----------------------------+---------------------------------+-----------------+
| 4                          | 3                               | 4               |
| 1                          | 3                               | 1               |
| Not Set                    | 3                               | 3               |
| 1                          | Not Set                         | INFINITE        |
+----------------------------|---------------------------------+-----------------+

BTW: the task interval is launch new task instance every 5 minutes, so they won't overlap in most test cases above.

From the result, just to say prematurely:

  1. if both options are set, the option in Trigger will take effect, and the option in Settings is by-passed.

  2. if only option in Settings is set, then it will take effect.

  3. if only option in Trigger is set, (ITaskSetting::ExecutionTimeLimit is not set), then no option take effect, the task scheduler system will never try to terminate the task no matter how long time it runs.

So is seems that, if you want the system automatedly try to terminate the task running for too long time, you should at least enable the "ExecutionTimeLimit" option in Task Settings. if you also enable the option in a specific trigger of the task, the trigger's option will supersede that in task settings and take effect on tasks launched by this trigger.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.