I'm creating a trigger for a task in Windows using Microsoft.Win32.TaskScheduler.DailyTrigger to run daily at 8am. That task repeats every hour but I want it to stop after 10 hours until it fires up again the next day.
In the Windows task scheduler application, under trigger you have something like "Repeat task every 1 hour for a duration of 10 hours".
The repeat task every hour I can do, but I can't find a way to do the "for a duration of". This is the code I have to set up the trigger so far, startTime is a DateTime set to 8am today.
var dailyTrigger = new DailyTrigger();
dailyTrigger.Repetition.Interval = TimeSpan.FromHours(1);
dailyTrigger.StartBoundary = startTime;
dailyTrigger.ExecutionTimeLimit = TimeSpan.FromMinutes(59);
I could do it with multiple triggers, but I was thinking if the application interface allows it there probably is a way to do it in code.
答案 0 :(得分:0)
Repetition.Interval
和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)
<强> IntervalMinutes 强>
获取或设置要重复运行的任务的执行之间的分钟数。
[...]
任务继续重复运行,直到指定的间隔为止 DurationMinutes属性到期。 IntervalMinutes值是 从上一次执行开始算起。
IntervalMinutes值必须小于DurationMinutes值。
<强> DurationMinutes 强>
获取或设置触发器触发后触发器保持活动状态的分钟数。
[...]
此属性与IntervalMinutes属性一起使用 在一段时间内反复运行任务。例如,开始一个 任务于上午8点并反复重启,直到下午5点 DurationMinutes值为540分钟(9小时)。
DurationMinutes值还可用于终止正在运行的任务 在任务的DurationMinutes属性到期后。
使用KillAtDurationEnd属性指定任务 在DurationMinutes到期后终止。 DurationMinutes的值必须大于或等于IntervalMinutes 设置。