Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to properly autoshutdown an app
Message
De
30/12/2013 14:25:35
 
 
À
30/12/2013 10:52:26
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01591090
Message ID:
01591107
Vues:
62
>Hi all,
>
>I have an app that runs on a server and I need it to autoshutdown each night. It *mostly* works but sometimes chokes on trying to shut down so I wonder if I have the code in the right order or right place:
>
>The app has one form and on that form I have a timer that fires every 15 seconds.
>
>In the timer's .timer() method, this code checks the time and tries to shut down after 11 pm:
>
>
>
>IF VAL(LEFT(TIME(),2)) >= 23
>
>   * release this form and then try to clear the read
>  ON ERROR
>  THISFORM .Release()
>
>   ON SHUTDOWN
>   CLEAR EVENTS
>   
>ENDIF
>
>
>
>Questions:
>
>1) is the order correct on the above commands?
>2) should this code be in some method of the form itself?
>3) it does not seem like I need a QUIT most of the time - would this be better?

With older versions of VFP there were some circumstances under which a timer control wouldn't fire e.g. while a menu is dropped down. I believe this has improved significantly with VFP9. But, there are still circumstances where it won't fire e.g. if VFP is busy doing something else, say in the middle of an intense SQL statement.

You may have this already but the first line of any .Timer event handler should be This.Enabled = .F.. This is to prevent multiple firings of the Timer event in case it takes longer than your interval (in your case, 15 seconds) to process the event, or there is any other condition that might otherwise cause the event to fire more than once. At the end of your event handler you re-enable the control.

Another good habit to get into with timer event handlers is to set a time variable once, near the beginning and reference that as the current "time" throughout the handler. Otherwise there are circumstances around midnight or hour change boundaries where multiple calls to TIME() can result in different hours or dates being returned within the same handler.

Depending on how the app is structured you may not need the ThisForm.Release() call at all. I'm wondering if that's causing release of the Timer control itself and statements below that are not executing.

CLEAR EVENTS is a normal way to cause a shutdown. Most apps have no code following their READ EVENTS (or perhaps just shutdown code) so issuing CLEAR EVENTS effectively shuts down the app. That said, it does no harm to add CANCEL or QUIT after READ EVENTS if it's not already present.

There is also an HOUR() function, and numeric hour never exceeds 23, so you could use IF HOUR( TIME( ) ) = 23 in place of your current construct.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform