Session.CurrentTime=Microseconds/1000000
Session.SpentTime=Session.CurrentTime - Session.StartTime
Session.SpentTimeMin=Session.SpentTime/60
Session.SpentTimeSec=Session.SpentTime -Session.SpentTimeMin*60
if Session.SpentTimeSec<10 then
Session.SpSec="0" + str(Session.SpentTimeSec)
else
Session.SpSec=str(Session.SpentTimeSec)
end
If Session.CurrentTime>=Session.FinishTime then
Timer1.mode=0
end if
For some reason, the timer never stops at 10:00 sharp.
For a test, I opened 10 tabs and started this app in all of them. The timers stopped at different times in all of them ranging from 10:10 to 11:26.
Why does not the timer stop as soon as it reaches the FinishTime?
The timer class is not a precision system. Timer action occurs “after at least Period milliseconds have passed”.
The documentation for Timer.Period mentions that “The rate that a Timer can actually fire depends on the speed of the host computer, the operating system, and other tasks the computer is doing.”
If you need guaranteed time precision, you’ll need to find an approach other than setting the timer period for your desired FinishTime. There are multiple approaches, but I don’t feel comfortable making a recommendation without knowing what your use case is.
Yes, understand what you mean by saying that the timer is not accurate. In the previous iteration of the timer, I was counting the timer cycles, and it was very inaccurate.
With the code in the original post, the condition to stop the timer uses the Microseconds for the current time and and calculated finish time.
The finish time is calculated in the Start button “Action” event by adding 10 min to the start time. This has nothing to do with the timer.
The timer is supposed to stop as soon as current time is equal or more than the finish time.
There could be other factors because of the ambiguous naming to Session or the fact that Timer.Action fires in a sessionless context. Honestly I would need an example project to find the exact reasoning.
My first post explains one of the most common gotchas to timers.
Just for confirmation are you talking Timer in a Webapp or WebTimer in a Webapp as a Timer in a webapp is server side and WebTimer in a webapp is client side. They are two different animals.
HI, Steve,
Thank you for pointing me to the differences between Timer and WebTimer. I am using the one that is instantiated via IDE and has WebTimer as its superclass. I believe it is a WebTimer that operates on the client’s side.
I am trying to learn about the difference between the two - can you guide me to the finger direction?
Thank you,
Val