Reputation: 8815
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?
Upvotes: 0
Views: 157
Reputation: 31394
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.
Upvotes: 1
Reputation: 8258
Sounds like you should execute each task on its own thread. IT will easy the configuration of timing and controlling start/stop of each task
Using the Timer control is a good option, if the tasks should execute every given time delta.
Upvotes: 0