如何从TaskService
对象获取计划任务的触发器信息?
StringBuilder sb = new StringBuilder();
TaskService st = new TaskService();
var tasks = st.RootFolder.GetTasks();
foreach (Microsoft.Win32.TaskScheduler.Task task in tasks)
{
sb.Append(task.Name+",");
sb.Append(task.someValueHere <<<---
sb.Append(task.LastRunTime + ",");
sb.Append(task.NextRunTime.ToString()+" ; ");
}
st.Dispose();
答案 0 :(得分:1)
您需要访问Definition
,然后访问Triggers
。例如:
foreach (var task in tasks)
{
//...
foreach (var trigger in task.Definition.Triggers)
{
//...access trigger properties here.
}
}