需要引用Microsoft.Win32.TaskScheduler.dll
public Form1()
{
InitializeComponent();
// Get the service on the local machine
TaskService ts = new TaskService();
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });
// 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);
// Remove the task we just created
ts.RootFolder.DeleteTask("Test");
}

本文介绍如何使用C#创建一个定期执行的任务,包括定义任务触发器及动作,并演示了通过TaskService类注册与删除任务的过程。
1604

被折叠的 条评论
为什么被折叠?



