17

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?

fixer1234
  • 28,064
alpav
  • 477

2 Answers2

10

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.

Iszi
  • 14,163
1

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 listed 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 set as: 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 it seems that, if you want the system automatically 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 it will take effect on tasks launched by this trigger.

Exlife
  • 41