IScheduledTaskProperties.CreatePeriod

Syntax

CreatePeriod(Type: ScheduledTaskPeriodType): IScheduledTaskPeriod;

Parameters

Type is a mode of setting the task execution period.

Description

The CreatePeriod method creates an object that contains settings of the task execution period.

Example

Executing the example requires that the repository contains a scheduled tasks container with the TASK_CONTAINER identifier and a unit with the Module_1 identifier. The unit contains the Main procedure.

Sub Main;

Var

MB: IMetabase;

CrInfo: IMetabaseObjectCreateInfo;

MObj: IMetabaseObject;

Exe: IExecuteSubScheduledTask;

Per: IScheduledTaskPeriodDaily;

Prop: IScheduledTaskProperties;

Date: DateTime;

Begin

MB := MetabaseClass.Active;

CrInfo := MB.CreateCreateInfo;

CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_TASK_EXECUTESUB;

CrInfo.Id := "MODULE_EXECUTOR";

CrInfo.Name := "Unit execution";

CrInfo.Parent := MB.ItemById("TASK_CONTAINER");

MObj := MB.CreateObject(CrInfo).Edit;

Exe := MObj As IExecuteSubScheduledTask;

Exe.Assembly := (MB.ItemById("Module_1").Bind As IModule).Assembly;

Exe.SubName := "Main";

Prop := Exe.Properties;

Per := Prop.CreatePeriod(ScheduledTaskPeriodType.Daily) As IScheduledTaskPeriodDaily;

Per.EveryDays := 3;

Date := DateTime.Now;

Per.StartDateTime := Date.Compose(Date.Year, Date.Month, Date.Day, 12, 0, 0, 0);

Per.StopDateTime := DateTime.AddMonths(Per.StartDateTime, 2);

Prop.Period := Per;

MObj.Save;

End Sub Main;

After executing the example a new task of unit execution is created in the scheduled tasks container. The unit will be running every three days at 12:00 during two months.

See also:

IScheduledTaskProperties