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