CreateScheduledTask

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.

Details and OptionsDetails and Options

  • CreateScheduledTask returns a ScheduledTaskObject expression representing the created task.
  • CreateScheduledTask creates a task, but does not start it. The task can be started using 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.

ExamplesExamplesopen allclose all

Basic Examples  (6)Basic Examples  (6)

Create a task:

In[1]:=
Click for copyable input
Out[1]=

Start the task:

In[2]:=
Click for copyable input
Out[2]=

Stop and remove it:

In[3]:=
Click for copyable input
Out[3]=

Create a task, which will evaluate every second:

In[1]:=
Click for copyable input
Out[1]=

Assign value to :

In[2]:=
Click for copyable input

Start the task:

In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=

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

In[1]:=
Click for copyable input
Out[1]=

Specify a date to activate the task:

In[1]:=
Click for copyable input
Out[1]=

Non-synchronized tasks:

In[1]:=
Click for copyable input
Out[1]=

Better synchronization:

In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input

Synchronize tasks using an auxiliary task:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input

The auxiliary task was removed:

In[5]:=
Click for copyable input
Out[5]=

Stop tasks:

In[6]:=
Click for copyable input

Remove all tasks:

In[7]:=
Click for copyable input
Introduced in 2010
(8.0)
| Updated in 2014
(10.0)