Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using a timer
Message
De
24/06/2016 10:15:52
 
 
À
22/06/2016 10:15:44
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Network:
Windows Server 2012 R2
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01637566
Message ID:
01637664
Vues:
94
>This.iRepeats = This.iRepeats - 1
> If This.iRepeats < 0
> Clear Events
> EndIfHello comunity
>
>I need to create a Form with a timer on it to run every 30 minutes. for display for example a messagebox, or coomand to SQL to display BROWLIST.
>
>I found this code for the timer:
>
>
>Public goShutdownTimer
>goShutdownTimer = CreateObject("ctmrshutdown")
>Read Events
>
>Define Class ctmrshutdown as Timer
>   iRepeats = 10
>   Interval = 500
>   
>   Procedure Timer()
>      This.Enabled = .F.
>      ? "ran at",Datetime(),time(), second()
>
>      
>      This.Enabled = .T.
>   EndProc
>EndDefine
>
>
>But when the timer Stop, all the program is closed !?
>
>Someone could give me a simple example for create programmatically a Form with a Timer . The purpose is when i define timer to run every 30 minutes, i can display for example a messagebox, and after than the timer is reset to 0 (zero) and restart again.
>
>Many thanks
>Best regards
>LS

Luís, this is a "simple example for create programmatically a Form with a Timer" that displays a messagebox every time it is fired (for 30 minutes, Interval property should be set to 30 * 60 * 1000 - for testing purposes, it is set to 10 seconds interval). As you can see, until the user reacts to the messagebox, the interval for the timer is not reset and the form does not respond to user interaction. This may be or not what you pretend.

If you intend to perform a query at a regular interval, you probably should isolate the query in its own private session, to prevent it confuse the application flow.
LOCAL loForm AS aFormWithATimer

m.loForm = CREATEOBJECT("aFormWithATimer")
m.loForm.Show(1)

DEFINE CLASS aFormWithATimer AS Form
	ADD OBJECT theTimer AS aTimer
	ADD OBJECT cmdQuit AS CommandButton WITH Caption = "Close"
	ADD OBJECT txtInput AS TextBox WITH Top = 30

	Fired = 0

	FUNCTION cmdQuit.Click
		Thisform.Release()
	ENDFUNC

ENDDEFINE

DEFINE CLASS aTimer AS Timer

	Interval = 10000

	PROCEDURE Timer
		Thisform.Fired = Thisform.Fired + 1
		MESSAGEBOX("This is modal, timer will not re-run until user reacts..." + TRANSFORM(Thisform.Fired))
	ENDPROC

ENDDEFINE
----------------------------------
António Tavares Lopes
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform