Windows TaskScheduler DailyTrigger runs for

I am creating a trigger for a task on Windows using Microsoft.Win32.TaskScheduler.DailyTrigger to run daily at 8am. This task is repeated every hour, but I want it to stop after 10 hours, until it starts again the next day.

In the Windows Task Scheduler application under the trigger, you have something like "Repeat the task every 1 hour for 10 hours."

Repeating the task every hour, I can do it, but I can’t find a way to do it “on time”. This is the code that I have to set to run so far, startTime is the DateTime set today at 8am.

var dailyTrigger = new DailyTrigger();
dailyTrigger.Repetition.Interval = TimeSpan.FromHours(1);
dailyTrigger.StartBoundary = startTime;
dailyTrigger.ExecutionTimeLimit = TimeSpan.FromMinutes(59);

I could do this with a few triggers, but I thought that if the application interface allows this, there is probably a way to do this in code.

+4
source share
1 answer

EDIT: I noticed below, this is a different class, and the OP probably downloaded the library from Codeplex . The following is still applicable, it is simple Repetition.Intervaland Repetition.Duration.

// Set the time in between each repetition of the task after it starts to 30 minutes.
tt.Repetition.Interval = TimeSpan.FromMinutes(60); // Default is TimeSpan.Zero (or never)
// Set the time the task will repeat to 1 day.
tt.Repetition.Duration = TimeSpan.FromDays(1); // Default is TimeSpan.Zero (or never)

https://msdn.microsoft.com/en-us/library/office/microsoft.office.excel.server.addins.computecluster.taskscheduler.trigger.intervalminutes(v=office.12).aspx

IntervalMinutes

Gets or sets the number of minutes between runs for a task that must be run repeatedly.

[...]

The task continues to repeat until the interval specified in the DurationMinutes property expires. The value of IntervalMinutes is equally counted from the beginning of the previous execution.

IntervalMinutes must be less than DurationMinutes.

https://msdn.microsoft.com/en-us/library/office/microsoft.office.excel.server.addins.computecluster.taskscheduler.trigger.durationminutes(v=office.12).aspx

DurationMinutes

, .

[...]

IntervalMinutes . , 8:00 .. 5:00 , DurationMinutes 540 (9 ).

DurationMinutes DurationMinutes .

KillAtDurationEnd, , DurationMinutes. DurationMinutes IntervalMinutes .

0

All Articles