2013-04-22 134 views
1

我正在嘗試創建一個計劃任務(使用計劃的任務包裝)每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"); 
      } 
     } 
    } 

回答

0

我相信你正在尋找的dailyTrigger.Repetition.Interval財產。

DateTime datetime = DateTime.Today; 
DateTime startDateTime = new DateTime(datetime.Year, datetime.Month, datetime.Day, 0, 0, 0); 
DailyTrigger dailyTrigger = new DailyTrigger { StartBoundary = startDateTime, Enabled = true, DaysInterval = 1 }; 
dailyTrigger.Repetition.Interval = TimeSpan.FromHours(23); 
dailyTrigger.Repetition.Interval = TimeSpan.FromHours(3); 
td.Triggers.Add(dailyTrigger); 

您可以使用每週觸發樣品上codeplex爲它增加了一個觸發器,從明天開始,將每隔一週火上週一和週六重複每10分鐘以下11個小時的參考

其他示例是here