IScheduledTaskPeriodOneTimeOnly.StartMode

Syntax

StartMode: TaskPeriodOneTimeStartMode;

Description

The StartMode property determines when the one-time task launch is performed.

Example

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

Sub UserProc;
Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    MObj: IMetabaseObject;
    Exe: IExecuteSubScheduledTask;
    Period: IScheduledTaskPeriodOneTimeOnly;
    Prop: IScheduledTaskProperties;
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_CONTAINTER");
    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;
    Period := Prop.CreatePeriod(ScheduledTaskPeriodType.OneTimeOnly) 
As IScheduledTaskPeriodOneTimeOnly;
    Period.StartMode := TaskPeriodOneTimeStartMode.OnLogon;
    Prop.Period := Period;
    MObj.Save;
End Sub UserProc;

Imports Prognoz.Platform.Interop.Etl;
Imports Prognoz.Platform.Interop.KeFore;
Imports Prognoz.Platform.Interop.Metabase;

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    MObj: IMetabaseObject;
    Exe: IExecuteSubScheduledTask;
    Period: IScheduledTaskPeriodOneTimeOnly;
    Prop: IScheduledTaskProperties;
Begin
    MB := Params.Metabase;
    CrInfo := MB.CreateCreateInfo();
    CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_TASK_EXECUTESUB 
As Integer;
    CrInfo.Id := 
"MODULE_EXECUTOR";
    CrInfo.Name := 
"Unit execution";
    CrInfo.Parent := MB.ItemById[
"TASK_CONTAINTER"];
    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;
    Period := Prop.CreatePeriod(ScheduledTaskPeriodType.stptOneTimeOnly) 
As IScheduledTaskPeriodOneTimeOnly;
    Period.StartMode := TaskPeriodOneTimeStartMode.tpotsmOnLogon;
    Prop.Period := Period;
    MObj.Save();
End Sub;

After executing the example a new task of unit execution is created in the scheduled tasks container. The unit is run once on connecting to the repository.

See also:

IScheduledTaskPeriodOneTimeOnly