I have the method below to create TaskScheduler for Windows using ASquare.WindowsTaskScheduler, and it works as expected.
public bool CreateTaskScheduler()
{
var file = $"{Setting.GetDirectory()}\\{Setting.GetSpacename()}.exe";
var response = WindowTaskScheduler
.Configure()
.CreateTask(TaskName, file)
.RunDaily()
.RunEveryXMinutes(5)
.Execute();
if (response?.ErrorMessage != null)
{
System.Console.WriteLine(response?.ErrorMessage);
}
return response != null && response.IsSuccess;
}
Now the requirement has change and I need to change the Duration time to Indefinitely.
So I tried to added following line to the code:
.RunDurationFor(TimeSpan.MaxValue)
It works but the max time was 168 minutes, I searched a bit and found this answer and this answer tried to change TimeSpan
inside .RunDurationFor
following:
try 1 new TimeSpan(0, 0, 0, 0, -1)
try 2 new TimeSpan(0, 0, 0, 0, Timeout.Infinite)
try 3 TimeSpan.FromMilliseconds(-1)
try 4 new TimeSpan(0, 23, 0, 0, 0)
When I run the code only try 4 create task Task Scheduler to 23 hours. But try 1, 2 and 3 does not return any exception but does not create the Task Scheduler.
My Question, any idea how what to write inside .RunDurationFor(//what to write here)
so it can be valid for creating an Indefinitely?