views:

35

answers:

2

I will do several tasks periodically in my app, but they have different period, how to do this?

  1. run each task in a separate timer thread.

  2. 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?

A: 

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.

Am
But i am think too many timer thread may result high resource comsumption
Benny
how many thread are you taking about?a single thread sleeping, waiting to be awaken by the OS is better (in performance) then a single thread constantly working, checking if something should happen.
Am
+1  A: 

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.

shf301