SiComponents Home Page SiComponents Forums
Here you will be able to get help and share your experience
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Task status not tsRunning when started 'manually'

 
Post new topic   Reply to topic    SiComponents Forums Forum Index -> VCL Scheduling Agent
View previous topic :: View next topic  
Author Message
someguy



Joined: 30 May 2004
Posts: 6

PostPosted: Tue Jul 06, 2004 6:45 am    Post subject: Task status not tsRunning when started 'manually' Reply with quote

I am trying to use the Task Scheduler component to create then immediately start (.Run) a task remotely.

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:

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' );

...
...
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2102

PostPosted: Tue Jul 06, 2004 4:17 pm    Post subject: Reply with quote

The solution is: you need to call Activate method in case you're supposing that any properties could be changed before this. Activate refreshes the values of all properties. So your code could be modified as following:
Code:
while (now() <= timeout) and (FRemoteTask.Status <> tsRunning) do
begin
    FRemoteTask.Activate;
    Application.ProcessMessages;
end;
if FRemoteTask.Status <> tsRunning then
      raise Exception.Create( 'Task did not start within timeout' );


P.S. In order to to run dummy tasks you don't need to have any dummy triggers.
Back to top
View user's profile Send private message
someguy



Joined: 30 May 2004
Posts: 6

PostPosted: Wed Jul 07, 2004 11:05 am    Post subject: Reply with quote

Thanks Igor, that works a treat.

Cheers!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SiComponents Forums Forum Index -> VCL Scheduling Agent All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by p h p B B  © 2001, 2005 p h p B B  Group