This project has moved. For the latest updates, please go here.

how to view the status of a Scheduled Task

Jun 20, 2011 at 2:24 PM

I have referenced teh microsoft.win32.taskscheduler, bersino n1.6.4141.23964 runtime version v2.0.50727.

I am able to return the name of the Scheduled tasks, is there a way to return the task status ie "could not start"

Coordinator
Jun 20, 2011 at 5:14 PM

There are a couple of properties on the Task object that may give you what you want. Task.State will indicate the current state of the registered task and Task.LastTaskResult will give you the return code from the last execution.

Jun 20, 2011 at 5:35 PM
Edited Jun 20, 2011 at 5:38 PM

If a task is not running i am unable to gather any information about those tasks.

the only operation i can get to loop though the list of tasks is there any other way to

return Name and status (task.lasttaskresult)

 

foreach (RunningTask rt in ts.GetRunningTasks(false))

{

 

}

 I have tried a foreach (task t in ts.gettask)

but get an error task does not contain a public definition for getenumerator

 

Coordinator
Jun 20, 2011 at 7:19 PM
foreach (Task t in ts.RootFolder.Tasks)
{
   Console.WriteLine("{0}: {1}", t.Name, t.LastTaskResult);
}

Just as a reminder, under Windows Vista and later there are multiple subfolders below the root. You may need to recurse the ts.RootFolder and find the subfolders. There is an example at http://taskscheduler.codeplex.com/wikipage?title=Examples. In the Documentation area of this site, there are a number of examples on how to use the various parts of the library.

Jun 20, 2011 at 7:39 PM

well slap me silly and call me a idiot.

Thanks.

is there a list of what the lasttaskrusults are?

Coordinator
Jun 20, 2011 at 10:22 PM
Edited Jun 20, 2011 at 10:25 PM

Please see the discussion at http://taskscheduler.codeplex.com/discussions/231339.