Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Timer, too often, too soon
Message
From
11/10/2009 19:19:54
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Timer, too often, too soon
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01428866
Message ID:
01428866
Views:
144
There are two situations that a timer does not handle correctly, as I see it.

1) The interval is set to 1 second. Its code takes only a fraction of a second to run. Another process takes 5 seconds. When the other process finishes, the timer fires 5 times in a row, all within the same second. This is an overkill of 4 firings.

2) The interval is set to 10 seconds. Its code can take less time, but there are situations that it will take more than 10 seconds, e.g. 30 seconds. After the process (let's say 30 seconds) the timer will fire again immediately. This too is overkill. It should indeed redo the process immediately, but not twice in a row.

Both situation require some dedicated programming. The first one can be tackled by having a property in which we store the time of this moment. It can be compared on the next call. Then we know how much time has elapsed. It the elapsed time is less than the interval, we may decide to skip the event.
* TIMER event
local lnS
lnS = seconds()
if ( m.lnS - thisform.nTimerSec ) < ( this.interval / 1000 ) - .05
    * do nothing
else
    * do whatever
endif
thisform.nTimerSec = m.lnS
The second one can in part be dealt with using the timer.Reset() method. However, in the case I sketched it would not lead to one immediate call. Instead it would lead to a call only after 10 seconds. A more elaborate piece of code is required here.

Any ideas?
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Next
Reply
Map
View

Click here to load this message in the networking platform