Vista/Win7 MonthlyDOW Trigger

This forum is designated to discuss SiComponents Scheduling Agent.
Post Reply
bigstar
Posts: 11
Joined: Tue Aug 02, 2005 1:09 am

Vista/Win7 MonthlyDOW Trigger

Post by bigstar »

I recently upgraded to VCL Scheduling Agent v2.0.7 and while testing to insure that the component and my application still work without any unexpected defeats I noticed a possible problem, either in my code or in the component I'm not entirely sure.

I am trying to define multiple weeks for a MonthlyDOW trigger and the demo only allows a single week so I cant test this. the windows task manager does allow this. Is this some funky limitation of the component?

This appears to be flawed and non-functional to me, Can you please post an example of how this should be done? Its not explained in the help file.

I assumed I would do it similar to the other properties that accept multiple selection. i.e. days

isiticov
Site Admin
Posts: 2271
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Hello,

Task Scheduler 1x interface doesn't allow to set-up multiple weeks for this kind of trigger and this caused to have this limitation in our port of Task Scheduler 2.x interface. We will try to find a way how this could be improved. Meantime you can use the following workaround:

Code: Select all

// Just sample code

procedure TMainForm.SetMonthlyDOWTrigger(Task: TTaskItem);
var
  imonthdow: IMonthlyDOWTrigger;
  Details: TTriggerDetails;
const
  VISTA_TASK_FIRST_WEEK = 1;
  VISTA_TASK_SECOND_WEEK = 2;
  VISTA_TASK_THIRD_WEEK = 4;
  VISTA_TASK_FOURTH_WEEK = 8;
  VISTA_TASK_LAST_WEEK = 16;
begin
  Task.Activate;
  if (not Task.TaskScheduler.RunningVistaOrLater) then
  begin
    Details := Task.Triggers[0].Details;
    Details.MonthlyDOW.wWhichWeek := TASK_SECOND_WEEK;
    Task.Triggers[0].Details := Details;
  end
  else
  begin
      // VISTA specific!
    imonthdow := Task.Triggers[0].GetVistaTrigger as IMonthlyDOWTrigger;
    imonthdow.WeeksOfMonth := VISTA_TASK_SECOND_WEEK or VISTA_TASK_THIRD_WEEK;
  end;
  Task.Triggers.UpdateTriggers;
end;
Best regards,
Igor Sitikov.

bigstar
Posts: 11
Joined: Tue Aug 02, 2005 1:09 am

Post by bigstar »

This is what I came up with and so far it seems to work with every combination I've tried.

procedure TTrigger.SetMonthlyDOWTrigger;
var
imonthdow: IMonthlyDOWTrigger;
X: Word;
begin
imonthdow := FInterfaceVista as IMonthlyDOWTrigger;
imonthdow.DaysOfWeek := FTaskTrigger._Type.MonthlyDOW.rgfDaysOfTheWeek;
X := FTaskTrigger._Type.MonthlyDOW.wWhichWeek;
imonthdow.RunOnLastWeekOfMonth := (X > 15);
if imonthdow.RunOnLastWeekOfMonth then
X := X - 16;
imonthdow.WeeksOfMonth := X;
imonthdow.MonthsOfYear := FTaskTrigger._Type.MonthlyDOW.rgfMonths;
imonthdow.StartBoundary := GetStartDateTime;
if (FTaskTrigger.rgFlags and TASK_TRIGGER_FLAG_HAS_END_DATE) = 1 then
imonthdow.EndBoundary := GetEndDateTime;
end;

function TTrigger.GetMonthlyDOWTrigger: TTaskTrigger;
var
imonthdow: IMonthlyDOWTrigger;
begin
imonthdow := FInterfaceVista as IMonthlyDOWTrigger;
FTaskTrigger._Type.MonthlyDOW.rgfDaysOfTheWeek := imonthdow.DaysOfWeek;
FTaskTrigger._Type.MonthlyDOW.wWhichWeek := imonthdow.WeeksOfMonth;
if imonthdow.RunOnLastWeekOfMonth then
FTaskTrigger._Type.MonthlyDOW.wWhichWeek := FTaskTrigger._Type.MonthlyDOW.wWhichWeek + 16;
FTaskTrigger._Type.MonthlyDOW.rgfMonths := imonthdow.MonthsOfYear;
BeginDate := GetStartVistaDateTime;
Result := FTaskTrigger;
end;

Post Reply