I found a way to check for running scheduled tasks, but I am not sure, if the blocking behaviour of Pause
is the best thing to do.
RunScheduledTask[Print["Bazinga!"], {5, 10}]
(* a lot of code *)
(* till the end of script *)
While[ Or@@ScheduledTasks[][[All, 5]], Print[DateString[]]; Pause[1]]
Output:
C:\Software\Dev>math -script test.m
"Wed 18 Jun 2014 21:14:15"
"Wed 18 Jun 2014 21:14:16"
"Wed 18 Jun 2014 21:14:17"
"Wed 18 Jun 2014 21:14:18"
"Wed 18 Jun 2014 21:14:19"
"Bazinga!"
...
"Bazinga!"
"Wed 18 Jun 2014 21:15:00"
"Wed 18 Jun 2014 21:15:01"
"Wed 18 Jun 2014 21:15:02"
"Wed 18 Jun 2014 21:15:03"
"Wed 18 Jun 2014 21:15:04"
"Bazinga!"
C:\Software\Dev>
Edit: Changed the index of "Running" boolean from -1 to 5. See the answer by Szabolcs.
Edit: Added the comments in the code sample to stress on the opportunity of doing stuff while the scheduler is running and now checking if ALL schedulers are done like is done in answer by Szabolcs.