Wait for scheduled tasks to finish