So I have an event that starts a timer. If another event happens I want to delay (or restart the period) of that timer so that I don’t have 5-10-15-20 timer.run.event firing, but instead just one timer.run.event at the end - after a waiting period and no further events occur.
I thought that is what WebTimer.Reset was for, but it is not working that way. So then I tried:
Timer1.RunMode = WebTimer.RunModes.Off
Timer1.Period = 2000
Timer1.RunMode = WebTimer.RunModes.Single
Thinking that stopping it, resetting the period, and starting it again might do the trick.
I’ve also tried moving the timer location from Browser to Server, but this too did not help.
Hi Jim, just to make sure I understand… you want to set a 2000ms period to run, but allow code to continually ‘nudge’ the timer, so that it doesn’t expire and execute (unless something else fails to nudge it along and keep it from firing)?
I use timers (in desktop apps, but I believe Web is the same) to have a period (say 5000ms for argument), and if that period expires then fire (e.g. “Communications with server is down”). And if a positive result happens along the way then I continue to ‘reset’ the timer’s period to 5000ms.
So, another piece of code will be executing and repeatedly reset the timer.period to a 5000ms period, and if this happens continually before the 5000ms timer expires then the timer is nudged, and the Action never fires.
Generally speaking WebTimers (the browser ones!) seem to be less “precise” than on the desktop. If the framework is on “idle” they might be precise (difficult to judge and to test), but when the timer fires it doesn’t yet mean that the framework will send a request to the server instantly(!).
I made so far bad experience with multiple browser webtimers for instance. If a routine is too long in one timer, it seems to influence the execution of any other web timer in the browser. I’m still on my own learning path how this works precisely.
You are correct on both replies. This is what I want, and eventually I do want the event to fire cause it checks on the previous events. There is just no sense to waste time processing until all events settle. Also the events are at the browser side, so that is where I originally located the timer.
It just appears the timer run event ALWAYS runs and I cannot reset the period again. So before I report this as a bug I wanted to verify there wasn’t something I missed or misunderstood. The Timer.Reset online doc is very weak about what actually happens.
The docs suggest leaving timers at the client browser as too many timers at the server can bog it down. I have not noticed issues either way, but I can always add more horse power to the server and it is the overall ‘experience’ for the user that matters no matter where the slowness of the application comes from. I have no control over the connection to the user or the users device.
I also tend to use single use timers to prevent what you are talking about, with the first line of timer.run being me.runmode = off - even in desktop applications; then if the process needs to continue re-enabling the timer at the end of the timer.run event.
William, what does that code look like? Is it just Timer1.Reset?
Hi Jim - I just made a quick Web app and tested it (and I get it to work pretty well).
Here’s what it looks like…
Timer1.Run > posts a MessageBox, is set with a period of 5000ms
Timer2.Run > simply sets Timer1.Period = 5000ms (but does that every 1000ms)
…so when the page opens Timer2 continually hits Timer1 with “Timer1.Period = 5000ms”, thus Timer1.Run never executes.
I put a button on the page, it simply does “Timer2.RunMode = WebTimer.RunModes.Off”. Then you’ll see Timer1.Run execute.
Hope that makes sense.