我正在尝试创建一个计划任务(使用计划任务包装器)每 3 小时触发一次。我每天都安装了任务,但即使在阅读了文档之后,也无法让它每隔几个小时运行一次。也不太确定LogonType。谁能让我知道我哪里出错了?
private void button1_Click(object sender, EventArgs e)
{
using (TaskService ts = new TaskService())
{
var androback = ts.GetTask("Andro_Inc_Backup");
bool taskExists = androback != null;
if (taskExists)
{
MessageBox.Show("Andromeda incremental backup task already installed");
}
else
{
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Incremental Backup";
td.Principal.LogonType = TaskLogonType.ServiceAccount;
td.Triggers.Add(new DailyTrigger { DaysInterval = 1 });
td.Actions.Add(new ExecAction("C:\\Rameses\\Program\\Inc_Cloud_Backup.exe", null));
const string taskname = "Inc_Backup";
ts.RootFolder.RegisterTaskDefinition(taskname, td);
MessageBox.Show("Incremental Backup Task Installed");
}
}
}