Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Are Timers useful?
Message
From
24/09/2001 15:15:12
Gerry Schmitz
GHS Automation Inc.
Calgary, Alberta, Canada
 
 
To
24/09/2001 09:51:37
Bruce Gordon
Wicks Broadcast Solutions, Llc
Vienna, Virginia, United States
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00559941
Message ID:
00560142
Views:
23
Timers are usefull for "controlling" processing, not for "breaking into" existing processing.

In your example, it would be better to do your own "timing"; eg. in the FOR ... NEXT loop, check the "time elapsed" using SECONDS() or GetTickCount() and then take the appropriate action. That is how most "game loops" operate: they are either timer driven, or use a loop and measure elapsed times (using interpolation or extrapolation when the "frames" are not equal).


>How can I get a timer on a form to receive timer events when other code in the form is running? DoEvents allows me to interrupt that code by pressing a button, but the timer events are not received until the end of the process.
>
>I am using VFP7. The test form has 2 buttons: Do Stuff and Message. Message just pops up a messagebox. The code for Do Stuff is shown below. The timer activated by Do Stuff (.Timer1) has, as its timer method, code to disable the timer, pop up a messagebox, and enable the timer again. Various labels on the form show the progress of the Do Stuff loop and how long it takes.
>
>
>* Do Stuff Click Code
>WITH ThisForm
>	LOCAL i, j, ltStart
>	.Timer1.interval = 1500
>	.Timer1.enabled = .T.
>	.lblNum.Caption = '0'
>	.lblSec.Caption = '0'
>	ltStart = SECONDS()
>	j = 0
>	FOR i = 1 TO 200000
>		DOEVENTS
>		j = j+1
>		.lblNum.Caption = ALLTRIM(STR(j))
>	ENDFOR
>	.lblSec.Caption = ALLTRIM(STR(SECONDS() - ltStart))
>EndWith
>
>
>Regardless of how I fiddle with AutoYield and use DoEvents, I cannot get the timer events to be sent to the timer while the loop is processing. However, with the code above, the Message button will fire, and, while its MessageBox is up, the loop is suspended, as .lblNum is not incremented.
>
>Any help greatly appreciated.
>
>Thanks,
>Bruce Gordon
Previous
Reply
Map
View

Click here to load this message in the networking platform