使用以下code example我创建了一项任务:
using (TaskService ts = new TaskService())
{
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
// Add a trigger that, starting tomorrow, will fire every other week on Monday
// and Saturday and repeat every 10 minutes for the following 11 hours
WeeklyTrigger wt = new WeeklyTrigger();
wt.StartBoundary = DateTime.Today.AddDays(1);
wt.DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Saturday;
wt.WeeksInterval = 2;
wt.Repetition.Duration = TimeSpan.FromHours(11);
wt.Repetition.Interval = TimeSpan.FromMinutes(10);
td.Triggers.Add(wt)
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition("Test", td);
}
}
但是如何以编程方式添加以下内容"发送电子邮件" Windows任务计划程序中显示的操作,用于我创建的任务: