How to disable "stop task if..."

Feb 18, 2011 at 7:54 PM

Under the Settings tab in the Task Scheduler GUI, "Stop the task if it runs longer than:" is being checked by default for my tasks. How can I use the managed wrapper to disable that setting--i.e., uncheck the box, so that there's no limit on how long the task will run?

Coordinator
Feb 22, 2011 at 4:41 PM

That UI element is associated with the TaskDefinition.Settings.ExecutionTimeLimit property. Setting that property to TimeSpan.Zero will have the task run indefinitely.

Feb 22, 2011 at 6:38 PM

I'm running into the same problem with this issue that I just documented in my other thread about security options settings. Again, here is the code I'm using:

TaskService ts = new TaskService();
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Run " + taskName + " at logon";
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
td.Principal.GroupId = "BUILTIN";
td.Principal.UserId = "Administrators";
LogonTrigger lTrigger = (LogonTrigger)td.Triggers.Add(new LogonTrigger());
td.Actions.Add(new ExecAction(taskAppLocation, null, null));
ts.RootFolder.RegisterTaskDefinition(taskName, td);

When I run this code, it has no impact on the "Stop the task if it runs longer than..." setting. The checkbox remains checked, and the combo box is set to 3 days. I don't understand what I'm doing wrong. Thanks for any help you can provide.

Feb 23, 2011 at 7:56 PM

It's working now with the ExecutionTimeLimit set to TimeSpan.Zero. There was something else going on with the wrong version of a .dll in my project, which I straightended out, and now the code works. Thanks!

Sep 14, 2012 at 2:41 AM

I have the save problem. When I set ExecutionTimeLimit to TimeSpan.Zero,  the checkbox keeps checked, and the time limit is set to 0 hrs 0 mins, the scheduled action will exit immediately  after started. How to solve this problem?  My enviroment is WinXP sp3 + .NET 4.0.

Coordinator
Sep 14, 2012 at 3:00 PM

I have tried this with the current build (1.8.3) on both XP and Windows 7 and the control behaves as it should: When the the TaskDefinition.Settings.ExecutionTimeLimit is set to TimeSpan.Zero, the checkbox is unchecked and the combobox is disabled. Please check your version.

On JoeyChaps earlier post, I want to make a comment for other readers: You cannot set both the Principal.GroupId and Principal.UserId properties. You use GroupId if the account is a group and UserId if an individual identity. Also, GroupId is not supported under XP (1.0).

May 26, 2013 at 4:57 AM
I just tried this with V1.9.4 in Windows XP SP3. Not sure what I'm doing wrong, but TimeSpan.Zero results in the checkbox being checked and 0,0 for the time limit. XP is not nearly as important to me, so I currently set the value to 999 hours for XP. My app needs to run in the background on startup. Would be nice to know how Joey fixed this.
Feb 3, 2014 at 5:57 PM
I have v2.0.3 and I'm having the same issue in XP SP3 where the "Settings.ExecutionTimeLimit" property is set to "TimeSpan.Zero", but the "Stop the task if it runs longer than..." is still checked. Thus, the task never executes. Is there some combination of settings that will uncheck the "Stop the task if it runs longer than..." option? It works perfectly under Win 7 or greater, but not XP SP3.
Coordinator
Feb 6, 2014 at 1:59 AM
This is fixed in release 2.0.4. Thank you for identifying the problem.
Marked as answer by dahall on 9/1/2015 at 10:11 AM