使用任务调度器在C#中调度作业
本文关键字:调度作业 任务调度 | 更新日期: 2023-09-27 18:21:35
我正在使用以下代码在c#中调度任务
TaskDefinition td = ts.NewTask();
DateTime t = ts.RootFolder.Tasks["Test"].LastRunTime;
td.RegistrationInfo.Description = "Does something";
td.Triggers.Add(new TimeTrigger(DateTime.Now + TimeSpan.FromSeconds(10)));
//td.StartBoundary = DateTime.Today + TimeSpan.FromHours(23);
td.Triggers.Add(new WeeklyTrigger
{
StartBoundary = DateTime.Today + TimeSpan.FromHours(2),
DaysOfWeek = DaysOfTheWeek.Friday
});
我想添加一周以上的天数。。。
我发现我可以通过使用来做到这一点
DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Tuesday | DaysOfTheWeek.Wednesday
| DaysOfTheWeek.Thursday | DaysOfTheWeek.Friday | DaysOfTheWeek.Saturday
但问题是,我想动态地做这件事。用户将选择星期几,然后我将设置。。。请帮忙怎么做。
您可以保留一个带有用户选择的整数列表
然后你可以做
foreach (int day in days)
{
td.DaysOfWeek |= (DaysOfTheWeek)day;
}