Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using wwipstuff
Message
 
To
28/12/1999 04:35:33
Quinn Mayo
Quantified Pty Ltd
Melbourne, Australia
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Miscellaneous
Thread ID:
00309091
Message ID:
00309096
Views:
21
G'Day Quinn,

My recollection is that timer events don't fire while others are firing, rather they are queued.

Tests confirm this.

The following form has a couple of timers on it and reports the start and finishing times of each timer's timer event (analysis follows listing and results):

Listing
PUBLIC oform1

oform1=NEWOBJECT('form1')
oform1.Show
RETURN


	**************************************************
*-- Form:         form1 (e:\temp\testtimers.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   12/28/99 09:26:09 PM
*
*
DEFINE CLASS form1 AS form


	Top = 0
	Left = 0
	Height = 250
	Width = 375
	DoCreate = .T.
	Caption = 'Form1'
	WindowState = 0
	Name = 'Form1'


	ADD OBJECT timer1 AS timer WITH ;
		Top = 10, ;
		Left = 100, ;
		Height = 23, ;
		Width = 23, ;
		Interval = 1000, ;
		Name = 'Timer1'


	ADD OBJECT timer2 AS timer WITH ;
		Top = 10, ;
		Left = 140, ;
		Height = 23, ;
		Width = 23, ;
		Interval = 1500, ;
		Name = 'Timer2'


	ADD OBJECT edtmessages AS editbox WITH ;
		Height = 206, ;
		Left = 10, ;
		Top = 40, ;
		Width = 355, ;
		Name = 'edtMessages'


	PROCEDURE Init
		declare Sleep in win32api integer tnMilisecs
	ENDPROC


	PROCEDURE Destroy
		_cliptext = this.edtMessages.value
	ENDPROC


	PROCEDURE timer1.Timer
		thisform.edtMessages.Value = thisform.edtMessages.Value + tran(seconds()) + ' Start ' + this.name + CR
		=sleep(this.interval * 2)
		thisform.edtMessages.Value = thisform.edtMessages.Value + tran(seconds()) + ' End  ' + this.name + CR
	ENDPROC


	PROCEDURE timer2.Timer
		thisform.edtMessages.Value = thisform.edtMessages.Value + tran(seconds()) + ' Start ' + this.name + CR
		=sleep(this.interval * 2)
		thisform.edtMessages.Value = thisform.edtMessages.Value + tran(seconds()) + ' End  ' + this.name + CR
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
Results
77198.18700000001 Start Timer1
77200.19 End  Timer1
77200.2 Start Timer2
77203.204 End  Timer2
77203.21400000001 Start Timer2
77206.21800000001 End  Timer2
77206.21800000001 Start Timer1
77208.22100000001 End  Timer1
77208.22100000001 Start Timer1
77210.224 End  Timer1
77210.224 Start Timer2
77213.228 End  Timer2
77213.228 Start Timer2
77216.23300000001 End  Timer2
77216.23300000001 Start Timer2
77219.23700000001 End  Timer2
77219.23700000001 Start Timer2
77222.24099999999 End  Timer2
77222.24099999999 Start Timer2
77225.246 End  Timer2
77225.246 Start Timer2
77228.25 End  Timer2
77228.25 Start Timer2
77231.254 End  Timer2
77231.254 Start Timer1
77233.257 End  Timer1
77233.257 Start Timer1
77235.25999999999 End  Timer1
77235.25999999999 Start Timer1
77237.26300000001 End  Timer1
77237.26300000001 Start Timer1
77239.266 End  Timer1
77239.266 Start Timer1
77241.269 End  Timer1
77241.269 Start Timer1
77243.272 End  Timer1
77243.272 Start Timer1
77245.274 End  Timer1
77245.274 Start Timer1
77247.277 End  Timer1
77247.277 Start Timer1
77249.28 End  Timer1
77249.28 Start Timer1
77251.283 End  Timer1
...
Analysis
The way I read this:

- The second timer (due to fire first at 77198.7) waits until the first timer's timer event has finished executing (77200.2). The second timer was due to fire again at 200.2 and this may have (just) fallen into the first timer's first event so it too was queued (fired at 203.2)

- Timer events seem to be queued even while the event is firing (so while the timer event for the timers takes twice as long as the firing interval, things will baloon out of control with the queue growing ever longer

Changing the code to
local lnInterval
local lnInterval
lnInterval = this.interval
this.interval = 0

thisform.edtMessages.Value = thisform.edtMessages.Value + tran(seconds()) + ' Start ' + this.name + CR
=sleep(lnInterval * 2)
thisform.edtMessages.Value = thisform.edtMessages.Value + tran(seconds()) + ' End  ' + this.name + CR

this.interval = lnInterval
removes this effect and the following results ensue:
78550.60000000001 Start Timer1
78552.603 End  Timer1
78552.613 Start Timer2
78555.618 End  Timer2
78555.628 Start Timer2
78558.632 End  Timer2
78558.64200000001 Start Timer1
78560.645 End  Timer1
78560.655 Start Timer1
78562.658 End  Timer1
78562.658 Start Timer1
78564.66100000001 End  Timer1
78564.66100000001 Start Timer1
78566.664 End  Timer1
78566.664 Start Timer1
78568.666 End  Timer1
78568.666 Start Timer1
78570.66899999999 End  Timer1
78570.679 Start Timer2
78573.68400000001 End  Timer2
78573.694 Start Timer2
78576.698 End  Timer2
78576.698 Start Timer2
78579.702 End  Timer2
78579.702 Start Timer2
78582.70699999999 End  Timer2
78582.70699999999 Start Timer2
78585.711 End  Timer2
78585.711 Start Timer2
78588.715 End  Timer2
78588.715 Start Timer2
78591.72 End  Timer2
78591.72 Start Timer2
78594.724 End  Timer2
So while one timer event fires (as many times as it is in the queue) the other timer event queues

Adding the property lTimerFiring to the form and changing the timer event to
if thisform.lTimerFiring
	return
endif

thisform.lTimerFiring = .t.

local lnInterval
lnInterval = this.interval
this.interval = 0

thisform.edtMessages.Value = thisform.edtMessages.Value + tran(seconds()) + ' Start ' + this.name + CR
=sleep(lnInterval * 2)
thisform.edtMessages.Value = thisform.edtMessages.Value + tran(seconds()) + ' End  ' + this.name + CR

this.interval = lnInterval
thisform.lTimerFiring = .f.
Results in
78910.879 Start Timer1
78912.88100000001 End  Timer1
78912.891 Start Timer2
78915.89600000001 End  Timer2
78915.906 Start Timer2
78918.91 End  Timer2
78918.92 Start Timer1
78920.923 End  Timer1
78920.933 Start Timer1
78922.936 End  Timer1
78922.936 Start Timer1
78924.939 End  Timer1
78924.939 Start Timer1
78926.942 End  Timer1
78926.942 Start Timer1
78928.94500000001 End  Timer1
78928.94500000001 Start Timer1
78930.947 End  Timer1
78930.95699999999 Start Timer2
78933.962 End  Timer2
78933.962 Start Timer2
78936.976 End  Timer2
78936.976 Start Timer2
78939.98 End  Timer2
78939.98 Start Timer2
78942.985 End  Timer2
78942.985 Start Timer2
78945.989 End  Timer2
78945.989 Start Timer2
78948.993 End  Timer2
78948.993 Start Timer2
78951.99800000001 End  Timer2
78951.99800000001 Start Timer2
78955.00200000001 End  Timer2
Note that this makes no difference as the requests are queued so the form's property is not evealuated when the timer is supposed to fire, just when it does fire (ie it's turn in the queue comes along)
To get around this problem you'd need to save the interval property of each timer on the form and set it to 0 at the start of the timer event and then reset each property at the end of the timer event.


This has ended up being rather longer than I originally intended, but I hope it makes thing clearer (e.g as mud <g>)

BTW, did you get down to the MCG today - It was pretty to watch on the TV. Tendulkar at his best and Lee burning in. Now that's a game. I think we might struggle to convince our american bretheren though.

Cheers,

Andrew

>Hi,
>I am using wwIpstuff to download html pages off the net at regular intervals using timers. Ive got two timers and two wwipstuff classes on a form. When one timer fires and starts the download (at this point, program freezes until page is downloaded) does the other timer continue counting or does it also freeze. If it doesnt freeze, what happens if that timer wants to fire whilst another page is being d/l?
>
>Thanks in advance
>
>Quinn


If we were to introduce Visual FoxBase+, would we be able to work from the dotNet Prompt?


From Top 22 Developer Responses to defects in Software
2. "It’s not a bug, it’s a feature."
1. "I thought I fixed that."


All my FoxTalk and other articles are available on my web site.


Unless specifically identified otherwise, anthing posted here is purely my opinion and may or may not reflect the policies or practices of Microsoft.
Previous
Reply
Map
View

Click here to load this message in the networking platform