Keep kernel running for execution of scheduled task

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.


A better way to check if any scheduled tasks are active is

Or @@ ScheduledTaskActiveQ /@ ScheduledTasks[]

The reason why this is better is that it uses an API, thus it is more likely to be robust against future changes in the structure of ScheduledTaskObject. In the Raspberry Pi version current as of 2014-06-18, ScheduledTaskObject includes extra options at the end so [[-1]] won't work for checking if a task is active ([[5]] will though).

Warning: ScheduledTaskActiveQ[], called without arguments, will crash the kernel. ScheduledTaskActiveQ is a public System` context symbol, but it does not seem to be documented.