Changing ThreadPeriodicTask so that when it is terminated the thread finishes its current cycle and then stops.