Queued Timers
-
I am using the System.Threading.Timer timer. Now if I have a interval set quite low say 10ms it is possible for my timer event handler to be queued as they cannot be prcessed because the UI thread is busy or another application is running. When the UI thread becomes free it then processes all the queued events at the same time. Is it possible to determine programmatically the number of timer event handlers that are being queued. I want to be able to determine when there is a build up of queued event handlers. Some code to demonstrate this would be useful. Also, is it possible to limit the number of timer event handlers that are queued? Thanks, Liam
-
I am using the System.Threading.Timer timer. Now if I have a interval set quite low say 10ms it is possible for my timer event handler to be queued as they cannot be prcessed because the UI thread is busy or another application is running. When the UI thread becomes free it then processes all the queued events at the same time. Is it possible to determine programmatically the number of timer event handlers that are being queued. I want to be able to determine when there is a build up of queued event handlers. Some code to demonstrate this would be useful. Also, is it possible to limit the number of timer event handlers that are queued? Thanks, Liam
The Timer your using doesn't use events at all, so what your asking is pointless. The Timer "Tick" calls your code directly using a seperate thread out of the thread pool for each "Tick". But, if you were referring to the Forms-based Timer, that uses a Timer Tick event.
LiamD wrote:
Is it possible to determine programmatically the number of timer event handlers that are being queued. I want to be able to determine when there is a build up of queued event handlers.
No. I think you're limited to Peeking at the next message in the message pump, without actually processing it. I don't think you can peek at the entire message queue. Also, this process would take longer than the 10ms you have between events.
LiamD wrote:
Also, is it possible to limit the number of timer event handlers that are queued?
No, it's not. The best you can do to prevent a stack of tick events is to disable the timer at the beginning of your Tick event handler code, then reenable it at the end. This will, of course, throw off your 10ms pace, but your code will be executing the Tick event as fast as possible. 10ms is not alot of time to do much. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome