State: ScheduledTaskState;
The State property returns task state at the current moment.
To get task execution history, use the IScheduledTask.GetResults property.
Executing the example requires that the repository has a scheduled tasks container with the SCHEDULEDTASKSCONTAINER identifier.
Add links to the Fore, Metabase system assemblies.
Sub UserProc;
Var
MB: IMetabase;
Cont: IScheduledTasksContainer;
Tasks: IMetabaseObjectDescriptors;
i: integer;
Task: IScheduledTask;
Begin
// Get current repository
MB := MetabaseClass.Active;
// Get a container of scheduled tasks
Cont := MB.ItemById("SCHEDULEDTASKSCONTAINER").Bind As IScheduledTasksContainer;
// Display state of all tasks
Tasks := Cont.Tasks;
For i := 0 To Tasks.Count - 1 Do
Task := Tasks.Item(i).Bind As IScheduledTask;
Debug.Write("Task: " + (Task As IMetabaseObjectDescriptor).Name + " State: ");
Select Case (Task.State As Integer)
Case 0: Debug.WriteLine("Inactive");
Case 1: Debug.WriteLine("Ready");
Case 2: Debug.WriteLine("Is Progress");
Case 3: Debug.WriteLine("Finished");
Case 4: Debug.WriteLine("Error");
End Select;
End For;
End Sub UserProc;
After executing the example tasks list and state of each task are displayed in the development environment console.
See also: