为了在Windows任务计划程序中每周安排一次任务(每周一次),我使用codeplex中的以下代码:
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
});
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("D:\\Tasks\\obj\\x86\\Debug\\Tasks.exe", "SPU", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Test", td);
如何安排一周6天(周日除外)执行的任务?
答案 0 :(得分:2)
我还没有尝试过,但DaysOfTheWeek
标有Flags
属性,因此您应该可以指定多天这样:
DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Tuesday | DaysOfTheWeek.Wednesday
| DaysOfTheWeek.Thursday | DaysOfTheWeek.Friday | DaysOfTheWeek.Saturday