You could use RunScheduledTask
RunScheduledTask
or its relatives for this. For example, to append a random integer to catch
once every two seconds you could do something like
catch = {};
task = RunScheduledTask[AppendTo[catch, RandomInteger[10]], 2];
You could also use CreateScheduledTask
CreateScheduledTask
which is similar to RunScheduledTask
except that the task won't be started automatically after it's been created. You'll have to use StartScheduledTask
StartScheduledTask
to start it manually.
To start and stop the scheduled task you can use StartScheduledTask[task]
and StopScheduledTask[task]
, respectively, and RemoveScheduledTask[task]
will remove the scheduled task once you're done with it.
Additional information about these functions is available in the Documentation CenterDocumentation Center.