views:

170

answers:

1

Ok, I know an object of System.Timer executed in the thread-pool, rather than in the UI thread. I also know that the System.Timer is thread-safe.

Say I have a collection of System.Timer objects. I can have all of them run and (unless i'm mistaken) they'll actually execute in the thread-pool.

Say I instead create a collection of threads, each thread running a System.Timer object to periodically perform their actions. Will the execution of these 'thread-contained' timers still occur within the system's thread-pool? Or will their execution take place inside the thread itself?

In other words: am i deceiving myself by running the timers inside of multiple threads as their execution will occur in the same thread-pool and thus execute at the same priority? Or is there an actual benefit (speed or otherwise) by having the timers execute inside of separate threads (exception handling and other threading perils notwithstanding)?

A third option would be to have a collection of timers, and have their Elapsed event kick off a thread for the process. Would this be the preferred option?

Also, can one change the priority of the thread-pool? Or is it better to run the process in a separate thread and then configure the priority of that thread.

Thanks!

+1  A: 

Personally I would go for the third option - having a collection of timers that run in the thread pool and kick of there individual threads on the Tick/Elapsed event - as it is much simpler to manage your threading operations that way.

A thread can be started, paused or stopped according to the value of your timers and your timers are all managed by the common thread pool - thus they all get a chance to increment.

Pho3niX