0
我正在使用任務計劃程序託管包裝從外部程序(SharePoint)創建計劃任務創建和讀取任務很好,但我找不到任何方法來編輯任務,一旦它被註冊,我是否必須重新註冊新任務或以某種方式執行更新請求?編輯任務計劃任務C#
註冊我的任務:
TaskDefinition newTask = taskService.NewTask();
newTask.RegistrationInfo.Description = (string)timerJobItem.FieldValues["Description"];
newTask.Principal.LogonType = TaskLogonType.InteractiveToken;
// Switch for different schedule options, use createTriggers method
List<Trigger> triggers = createTriggers((string)timerJobItem["Schedule"], (DateTime)timerJobItem["StartTime"]);
newTask.Triggers.Add(triggers.First());
// Create Action to add to new Task
newTask.Actions.Add(new ExecAction((string)timerJobItem["Action"], (string)timerJobItem["Arguments"], null));
// Create Task
taskService.RootFolder.RegisterTaskDefinition(jobName, newTask);
接着我在其中找到工作的調度任務,但是當我試圖做出改變什麼也沒有發生:
// Method to get all Tasks that match a name - Working
private Task[] GetAllTasks(string regexString)
{
Regex regex = new Regex(String.Format(@"{0}", regexString));
using (TaskService taskService = new TaskService())
{
Task[] allTasksCollection = taskService.FindAllTasks(regex, true);
foreach (Task task in allTasksCollection)
{
Console.WriteLine(task.Name);
}
return allTasksCollection;
};
}
....
// Get a single timer job
Task[] allTimerJobs = GetAllTasks(prefix);
List<Task> allTimerJobsList = allTimerJobs.Cast<Task>().ToList();
string jobName = String.Format("{0}[{1}].{2}", prefix, (int)timerJobItem["ID"], jobReference);
// Get Task by name
int indexOfJob = allTimerJobsList.FindIndex(t => t.Name == jobName);
Task matchingJob = allTimerJobsList[indexOfJob];
// No Error but nothing happens to task
matchingJob.Definition.Triggers.Clear();
// No Error but nothing happens to task
matchingJob.Definition.Settings.Enabled = false;
TIA