({{, CreateScheduledTask[expr] 
creates a local scheduled task that will repeatedly evaluate expr once per second.}, {, CreateScheduledTask[expr,time] 
creates a task that will repeatedly evaluate expr every time seconds.}, {, CreateScheduledTask[expr,{time}]
creates a task that will evaluate expr once after time seconds.}, {, CreateScheduledTask[expr,{time,count}]
creates a task that will try evaluating expr once every time seconds up to count times total.}, {, CreateScheduledTask[expr,timespec,start]
creates a task that will evaluate expr according to timespec starting at start time.}})

OpenersNotesSection(Spacer1)Details and Options

CreateScheduledTask returns a (RefLink[ScheduledTaskObject, paclet:ref/ScheduledTaskObject]) expression representing the created task.

CreateScheduledTask creates a task, but does not start it. The task can be started using (RefLink[StartScheduledTask, paclet:ref/StartScheduledTask]).

CreateScheduledTask creates a task to be run locally in the current Wolfram Language session. No task state is preserved between sessions.

The start is taken to be the absolute time when the task is activated.

The first evaluation of expr will occur time seconds after it is activated.

If two tasks are scheduled to evaluate at the same time, the one added later will execute first.

Scheduled tasks do not require a notebook front end to work.

By default, if the time necessary to evaluate expr is larger than time, the next pending evaluation is skipped.

OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (6)

Create a task:

t=CreateScheduledTask[Print[DateString[]]]

Start the task:

StartScheduledTask[t]

Stop and remove it:

RemoveScheduledTask[t]

Create a task, which will evaluate x every second:

t=CreateScheduledTask[x]

Assign value to x:

x:=Print[DateString[]];

Start the task:

StartScheduledTask[t]

RemoveScheduledTask[t]

Create a task that will be activated 5 seconds from the current time and will print 1 second later:

RunScheduledTask[MessageDialog["text"],{1},AbsoluteTime[]+5]

Specify a date to activate the task:

RunScheduledTask[MessageDialog["text"],{1},AbsoluteTime[{2010,3,12,15,16,0}]]

Non-synchronized tasks:

i=0;
RunScheduledTask[++i, 1];
RunScheduledTask[i=0,4];
Dynamic[i]

Better synchronization:

j=0;
StartScheduledTask[{CreateScheduledTask[++j, 1],CreateScheduledTask[j=0,4]}];
Dynamic[j]

RemoveScheduledTask[ScheduledTasks[]];

Synchronize tasks using an auxiliary task:

n=1;Dynamic[FlipView[{Graphics[{Red,Disk[]}],Graphics[{Green,Disk[]}]},n]]

x1=CreateScheduledTask[StartScheduledTask[{x3}];RemoveScheduledTask[$ScheduledTask],{0.3}];
x2=CreateScheduledTask[n=1,1];
x3=CreateScheduledTask[n=2,1];

ScheduledTasks[]

StartScheduledTask[{x1,x2}];

The auxiliary task x1 was removed:

ScheduledTasks[]

Stop tasks:

StopScheduledTask[ScheduledTasks[]];

Remove all tasks:

RemoveScheduledTask[ScheduledTasks[]];

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[AbsoluteTime, paclet:ref/AbsoluteTime])  ▪  (RefLink[Clock, paclet:ref/Clock])  ▪  (RefLink[Refresh, paclet:ref/Refresh])  ▪  (RefLink[ScheduledTask, paclet:ref/ScheduledTask])  ▪  (RefLink[CloudDeploy, paclet:ref/CloudDeploy])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Date and Time Functions, paclet:tutorial/DateAndTimeFunctions])}, {▪(RefLinkPlain[Controlling Infinite Evaluation, paclet:tutorial/ControllingInfiniteEvaluation])}})}})