The task starts correctly and appears as 'Running' in the Windows Schduler but the component's Status is still shows tsNotScheduled.
I've tried creating a dummy 'Once off' trigger set to 10 years in the future but this didn't fix the problem.
Is there a way to get the 'true' status of a task started in this way?
If it helps, here's a sample of the code being used...
Code: Select all
FTaskScheduler := TTaskScheduler.Create(nil);
FTaskScheduler.TargetMachine := 'THOR';
if not FTaskScheduler.StartScheduler then
raise Exception.Create( 'Failed.' );
FTaskScheduler.Open();
FRemoteTask := FTaskScheduler.CreateNewItem( ... );
FRemoteTask.ApplicationName := ....
FRemoteTask.SetAccountInformation( ... );
FDummyTrigger := FRemoteTask.Triggers.Add();
FDummyTrigger.BeginDate := IncYear(Now(),10);
FDummyTrigger.HasEndDate:= false;
FDummyTrigger.TriggerType := ttOnce;
FDummyTrigger.Enabled := true;
FRemoteTask.Save;
FRemoteTask.Activate;
// Run the remote task
//
FRemoteTask.Run;
timeout := IncSecond(Now(), 10);
while (now() <= timeout) and (FRemoteTask.Status <> tsRunning) do
SleepEx(20, true);
if FRemoteTask.Status <> tsRunning then
raise Exception.Create( 'Task did not start within timeout' );
...
...