I will do several tasks periodically in my app, but they have different period, how to do this?
-
run each task in a separate timer thread.
-
run all the period task in the same timer thread, but check the time to see if the task should be activated.
do you have any better solution?
It would mostly depend on how many tasks you have to run.
With two or three tasks it would make sense to keep have a separate timer for each task, but will get unwieldy with more tasks.
If there a good number of tasks I would have single timer that checks a list of tasks to see if there are any tasks ready to run. That way to add a task; just add it to the list. Having a list of tasks would also make it easy for the tasks to be data driven.