C#如何获取触发器信息

时间:2017-05-25 19:35:51

标签: c# taskscheduler

如何从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();

1 个答案:

答案 0 :(得分:1)

您需要访问Definition,然后访问Triggers。例如:

foreach (var task in tasks)
{
    //...
    foreach (var trigger in task.Definition.Triggers)
    {
        //...access trigger properties here.
    }
}