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.
source
share