Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to determine if timer is working in another session
Message
De
28/10/1999 15:09:38
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00283292
Message ID:
00283332
Vues:
15
>I have a form that has a timer. Every time I run this form the timer kicks in and does some process. I was wondering, if had 5 users running the form at the same time will that kickoff 5 seperate timers. How do I determine if my timer is running so that I don't kick of the timer each time a new user uses my form? Help appreciated?
>

If each is on a separate machine, there's no IPC mechanism available to see what's running on another system. You'd need some sort of semaphone mechanism to let you know that another system is already running a timer.

One method would be to use a table visible to all systems. Each form instance starts its own timer. In the timer's Timer event, you check to see if you can open the common table for exclusive access or if it's already opened, and only fire the event code bwhen hoilding exlcusive access to the table, something like:
DEFINE CLASS tmrSemaphoreLockedEvent AS TIMER
PROCEDURE TIMER
   LOCAL cOldErrHand
   IF ! USED('<i>semaphore table</i>')
      cOldErrHand = ON('ERROR')
      ON ERROR *
      USE <i>semaphore table</i> EXCLUSIVE IN 0
      ON ERROR &cOldErrHand
   ENDIF
   IF USED('<i>semaphore table</i>')
      * fire the activity
   ENDIF
   this.Reset()
ENDPROC

PROCEDURE DESTROY
   IF USED('<i>semaphore table</i>')
      USE IN '<i>semaphore table</i>
   ENDIF
   =DODEFAULT()
ENDPROC
ENDDEFINE
Obviosuly, you need to add code, set properties, etc, and you have to establish names, durations, intervals, etc. But it's a skeleton to start on.

The code above would allow multiple instances of the form to run in private data sessions in a single VFP session, or multiple instances of the VFP app on a single station, as well as single/multiple sessions on multiple stations; only one timer at most would acquire the lock at any given time regardless of what went on.

If a station crashes while holding the lock, the first timer that tries to get the lock after the server sees that the system holding the lock dies and releases the lock will take over the timer-fired task. if the server doesn't release the lock when the system crashes, then noone will run the process until the lock is cleared.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform