使用以下code example電子郵件我創建了一個任務:如何發送使用C#任務計劃託管包裝
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任務計劃程序的顯示下面的「發送電子郵件」行動我創建的作業。:
使用你的建議,我成功地創建了電子郵件操作過程中結合的行動。但是,如果任務失敗,我想發送一封電子郵件。所以我[在這裏創建了一個新帖子](http://stackoverflow.com/questions/32018859/using-c-sharp-task-scheduler-managed-wrapper-how-to-trap-an-error-if-task-失敗)。 – nam