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.
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