Windows TaskScheduler DailyTrigger 运行 持续时间

Windows TaskScheduler DailyTrigger run for a duration of

我正在使用 Microsoft Windows 中的任务创建触发器。Win32.TaskScheduler.DailyTrigger 到 运行 每天早上 8 点。该任务每小时重复一次,但我希望它在 10 小时后停止,直到第二天再次启动。

在 Windows 任务调度程序应用程序中,在触发器下你有类似 "Repeat task every 1 hour for a duration of 10 hours" 的东西。

每小时的重复任务我可以做,但是我找不到办法做"for a duration of"。到目前为止,这是我必须设置触发器的代码,startTime 是一个设置为今天上午 8 点的日期时间。

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

我可以用多个触发器来完成,但我在想如果应用程序接口允许的话,可能有一种方法可以在代码中完成。

编辑:我注意到下面是一个不同的 class,OP 可能已下载 a library from Codeplex。以下仍然适用,只是 Repetition.IntervalRepetition.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 executions for a task that is to run repeatedly.

[...]

The task continues to run repeatedly until the interval specified in the DurationMinutes property expires. The IntervalMinutes value is counted from the start of the previous execution. The

IntervalMinutes value must be less than the DurationMinutes value.

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

DurationMinutes

Gets or sets the number of minutes that the trigger remains active after the trigger fires.

[...]

This property is used in conjunction with the IntervalMinutes property to run a task repeatedly for a period of time. For example, to start a task at 8:00 A.M. and repeatedly restart it until 5:00 P.M., the DurationMinutes value would be 540 minutes (9 hours).

The DurationMinutes value can also be used to terminate a running task after the DurationMinutes property for the task expires.

You use the KillAtDurationEnd property to specify that the task is terminated after its DurationMinutes expires. The value of DurationMinutes must be greater than or equal to the IntervalMinutes setting.