Problem in Enable/Disable a Task

This forum is designated to discuss SiComponents Scheduling Agent.
Post Reply
partha
Posts: 5
Joined: Tue May 10, 2005 5:22 am

Problem in Enable/Disable a Task

Post by partha »

Hello,

I am having problem in enabling/disabling a task. I am using the folowing code but the changes are not getting saved:

var
Index : Integer;
Task: TTaskItem;
begin
for Index := 0 to Scheduler.Count - 1 do begin
Task := Scheduler.Items[Index];
Task.Activate;
if SetActive then //SetActive is procedure parameter
Task.Flags := Task.Flags + [tfDisabled]
else
Task.Flags := Task.Flags - [tfDisabled];
Task.Save;
end;
end;


Any help will be appreciated.

thanks and regards,
Partha
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Do you get any error? May be using

Code: Select all

Task.Deactivate(True);
instead of

Code: Select all

Task.Save;
will help? How do you see that changes are not saved? Do you make "refresh"?
partha
Posts: 5
Joined: Tue May 10, 2005 5:22 am

Post by partha »

I tried both

Task.Deactivate(True);
and
Task.Save;

None of them work. I do not get an error but the status is not updated.

I am not displaying it to any control so I do not need a refresh.
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

This really strange. There is no any "problematic" place in your code.
I do not get an error but the status is not updated.
But where do you "see" this status if you don't display it? Directly in Scheduled Tasks? Then Status column doesn't change on adding Disabled flag, but only Schedule and Next Run coulmns indicates Disabled.
partha
Posts: 5
Joined: Tue May 10, 2005 5:22 am

Post by partha »

I check directly in windows scheduler. Also with,
Task.EditWorkItem
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

:) There is small bug in your source and I can suppose it is the origin of problem. Instead of

Code: Select all

if SetActive then //SetActive is procedure parameter 
Task.Flags := Task.Flags + [tfDisabled] 
else 
Task.Flags := Task.Flags - [tfDisabled]; 
shall be used

Code: Select all

if SetActive then //SetActive is procedure parameter 
Task.Flags := Task.Flags - [tfDisabled] 
else 
Task.Flags := Task.Flags + [tfDisabled]; 
Please let us know if this fixes the problem.
partha
Posts: 5
Joined: Tue May 10, 2005 5:22 am

Post by partha »

Thanks, it solves this. :)
Post Reply