ITaskService s = new TaskSchedulerClass();
s.Connect(
this.ControllerName,
Configuration.UserName,
Configuration.Domain,
Configuration.Password);
ITaskFolder tf = s.GetFolder("\\");
IRegisteredTaskCollection allTask = null;
IRunningTaskCollection allTaskRunning = s.GetRunningTasks(0);
我可以使用IRunningTaskCollection
获取正在运行的任务,但找不到就绪任务。
答案 0 :(得分:0)
遗憾的是,没有一种方便的方法,但你可以编写自己的方法。使用递归遍历任务文件夹层次结构。像这样......
private static List<IRegisteredTask> GetReadyAndRunningTasks(
ITaskFolder folder,
List<IRegisteredTask> readyAndRunningTasks = null)
{
if (readyAndRunningTasks == null)
{
readyAndRunningTasks = new List<IRegisteredTask>();
}
IRegisteredTaskCollection tasks = folder.GetTasks(flags: 0);
foreach (IRegisteredTask task in tasks)
{
if (task.State == _TASK_STATE.TASK_STATE_READY
|| task.State == _TASK_STATE.TASK_STATE_RUNNING)
{
readyAndRunningTasks.Add(task);
}
}
foreach (ITaskFolder subFolder in folder.GetFolders(flags: 0))
{
GetReadyAndRunningTasks(subFolder, readyAndRunningTasks);
}
return readyAndRunningTasks;
}
然后像这样称呼它......
List<IRegisteredTask> readyAndRunningTasks
= GetReadyAndRunningTasks(s.GetFolder(Path: "\\"));