On Timers
Posted: Sun Sep 11, 2011 2:50 am
Hi all.
Up until recently, I have only used "countdown" timers - that is timers that are activated only when a user does something, and that deactivate themselves immediately upon firing. These are fairly easy to deal with, and they don't get in the way much.
Now I have a need for a permanent "polling" timer for keeping a GUI up to date, and have the problem of the timer going off far more often than I want it to. For example, it appears that the onTimer event stacks up on the queue when menus are visible. If the user opens a drop down menu, and does not make a selection but pauses there for a while, then upon cancelling the menu, the timer callback may then fire a bunch of times in immediate succession. I assume there are other cases where this may happen (though a modal []DQ does not appear to be one of those).
This problem can be handled by having the timer callback function track the time it last fired, and exiting early if the actual interval is much shorter than the specified interal, which is in fact what I have done.
Another problem is when debugging, you have the timer going off repeatedly which can be annoying. Other than explicitly de-activating the timer or timers when debugging I can't think of any way to avoid this.
Yet another issue is that when closing the parent form of a timer whose job it is to keep the form up-to-date, you can get a value error situation ... I suppose the close callback can see if the timer callback is running and wait for it to finish somehow...
Anyway, my question is for those of you who are experienced with timers, any thoughts or pointers or tips or tricks to share? I'm sure I'm going to run into more issues that I have not thought of.
Up until recently, I have only used "countdown" timers - that is timers that are activated only when a user does something, and that deactivate themselves immediately upon firing. These are fairly easy to deal with, and they don't get in the way much.
Now I have a need for a permanent "polling" timer for keeping a GUI up to date, and have the problem of the timer going off far more often than I want it to. For example, it appears that the onTimer event stacks up on the queue when menus are visible. If the user opens a drop down menu, and does not make a selection but pauses there for a while, then upon cancelling the menu, the timer callback may then fire a bunch of times in immediate succession. I assume there are other cases where this may happen (though a modal []DQ does not appear to be one of those).
This problem can be handled by having the timer callback function track the time it last fired, and exiting early if the actual interval is much shorter than the specified interal, which is in fact what I have done.
Another problem is when debugging, you have the timer going off repeatedly which can be annoying. Other than explicitly de-activating the timer or timers when debugging I can't think of any way to avoid this.
Yet another issue is that when closing the parent form of a timer whose job it is to keep the form up-to-date, you can get a value error situation ... I suppose the close callback can see if the timer callback is running and wait for it to finish somehow...
Anyway, my question is for those of you who are experienced with timers, any thoughts or pointers or tips or tricks to share? I'm sure I'm going to run into more issues that I have not thought of.