Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about timers 1

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
GB
Ive an application that needs to poll 3 seperate message queues, and so the thinking is that I should just allocate 3 timers, and set each one with a delegate to trigger each time the timer is completed.

This has got me thinking,

When the delegate is fired, does it exist in the same thread as the calling code, or does it temporarily spawn a new thread to execute in, before returning back to the main code thread.

If the delegates all fire in the main thread and stay there, then what will happen when timer ones delegate is firing, and Timer two's is triggered. Does Timer 2 wait, or does it pause Timer 1s operation temporarily?

Logic tells me that as you may not have stopped the timer, the OnTimerComplete event should execute in its own thread to prevent the timers clashing, but as this is a critical piece of code I'd rather not assume anything. (And as 2 of the timer complete event handlers need access to some of the same objects, I need to know if I have to write code to prevent them clashing)

Cheers

K
 
You'll want to start each timer on it's own thread otherwise you'll run into problems. The code will execute all the first timers events before it moves on to the second one which could cause an overlap into the other timers events before it's next tick. Look at using System.Threading.Timer, this will work much better imo.

-jhaith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top