Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Timers
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Re: Timers
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01521261
Message ID:
01521308
Views:
80
In the code below, a timer:

- is not affected by INKEY()
- blocked by Sleep API
- runs behind a MESSAGEBOX dialog

One can clearly notice that an execution of a method, or a call, or some background household activity definitely slows it down a bit.
CLEAR
PUBLIC oForm
oForm = CREATEOBJECT('MyForm')
oForm.Visible = .T.

DEFINE CLASS MyForm As Form
	Autocenter = .T.
	MessageBoxShown = .F.
	StoredSeconds = 0

	ADD OBJECT Timer1 As Timer

PROCEDURE Activate
	WITH THIS
		IF NOT .MessageBoxShown
			.MessageBoxShown = .T.
			.StoredSeconds = SECONDS()
			.Timer1.Interval = 500

			.WriteStr('INKEY fires...')
			= INKEY(2) && 2 seconds

			.WriteStr('SLEEP fires...')
			DECLARE Sleep IN kernel32 INTEGER dwMilliseconds
			= Sleep(2000) && 2 seconds

			.WriteStr('MESSAGEBOX fires...')
			= MESSAGEBOX(VERSION())
			.WriteStr('MESSAGEBOX exited')
		ENDIF
	ENDWITH

PROCEDURE WriteStr(vValue)
	ACTIVATE SCREEN
	? vValue

PROCEDURE Timer1.Timer
	nNewSeconds = SECONDS()
	ThisForm.WriteStr(nNewSeconds - ThisForm.StoredSeconds)
	ThisForm.StoredSeconds = nNewSeconds

ENDDEFINE
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform