This project has moved. For the latest updates, please go here.

Set ExecutionTimeLimit to TimeSpan.Zero doesn't work

Topics: Errors
Jan 9 at 2:39 PM
Edited Jan 9 at 3:14 PM
I'm using the TaskScheduler.dll (version 2.5.21) in order to create a new task.
I want my task to run indefinitely, for that I'm setting the ExecutionTimeLimit property to TimeSpan.Zero.
When I execute my code in windows10 It works perfectly but in windows7 it doesn't work: "Stop the task if runs longer than" is checked and the value is 3 days....
Here is the code where I set all taslSettings:
   settings.AllowHardTerminate = true;
  settings.DisallowStartIfOnBatteries = false;
  settings.Enabled = true;
  settings.IdleSettings.RestartOnIdle = false;
  settings.IdleSettings.StopOnIdleEnd = false;
  settings.MultipleInstances = TaskInstancesPolicy.IgnoreNew;
  settings.RunOnlyIfIdle = false;
  settings.StopIfGoingOnBatteries = false;
  settings.ExecutionTimeLimit = TimeSpan.Zero;
  settings.Compatibility = TaskCompatibility.V1;
Is there a known issue for that? How could I manage to solve my problem?
Thanks!!
Jan 9 at 3:15 PM
Edited Jan 10 at 7:36 AM
Additional information: I just see that It does not work since I change the Compatibility to TaskCompatibility.V1
Any idea to solve this problem?
Coordinator
Jan 10 at 2:57 PM
When the TaskCompatibility.V1 is set (and I would recommend against it as the library will auto downgrade for XP) then you are working with the 15 year old task library and the ITask.SetMaxRunTime method which has proven a bit inconsistent in Vista and later. One of the bugs I've tried to work around may be causing your trouble. Here's the code from the workaround (in Task.cs) so you can see what's happening:
// Due to an issue introduced in Vista, and propagated to Windows 7, setting the
// MaxRunTime to INFINITE results in the task only running for 72 hours. For
// these operating systems, setting the RunTime to "INFINITE - 1" gets the
// desired behavior of allowing an "infinite" run of the task.
uint ms = value == TimeSpan.Zero ? InfiniteRunTimeV1 : Convert.ToUInt32(value.TotalMilliseconds);
v1Task.SetMaxRunTime(ms);
if (value == TimeSpan.Zero && v1Task.GetMaxRunTime() != InfiniteRunTimeV1)
   v1Task.SetMaxRunTime(InfiniteRunTimeV1 - 1);
I would strongly recommend not setting the V1 flag and letting the library choose the best version of the native implementation to do the work.
Marked as answer by dahall on 1/10/2017 at 7:58 AM