>*!* MAIN PROGRAM Variable declaration >m._nFormTimeoutInSeconds = 600 >*!* number of seconds inactivity to trigger timeout >m._tLastUseractivityDateTime = DATETIME() >*!* last time that activity was detected >m._nLastKeyPressedbyuser = 0 >*!* stores the last key pressed >m._cLastMousePosition = "0,0" >*!* MROW,MCOL values as string indicating the last mouse position detected. >m._lApplicationIsBusyProcessing = .T. >*!* set to .t. when running long processed and .f. when finished. >m._cAutoShutdownFlagFile = "Shutdown4Maintenance.mem" >*!* name of a file to check for to detect that the application >*!* requires shutdown for maintenance >m._cApplicationInUseSharedFile = "MYAPPLICATIONINUSE.MEM" >*!* Open this file using fopen readonly when starting application >m._nApplicationIsAliveFileHandle = 0 >*!* file handle for m._cApplicationInUseSharedFile >*!* if performing sys manintenance try to open read-write unbuffered >*!* if you can do this no one is using the application. >*!* >m._nWaiting4UserToFinish = 2 >*!* number of wait cycles to wait for user to complete what he is doing >*!* before quitting when force shutdown is requested >m._nWaiting2QuitCountdown = 0 >*!* countdown vasriable to check when autoshuttingdown > >IF FILE(m._cAutoShutdownFlagFile) > *!* forced shutdown is detected > MESSAGEBOX("Application is unavailable due to system maintenance. Try again later. Quitting...") > QUIT >ENDIF >m._nApplicationIsAliveFileHandle = FOPEN(m._cApplicationInUseSharedFile,0) >IF m._nApplicationIsAliveFileHandle < 0 > *!* application is being used exclusively for maintenance > MESSAGEBOX("Application is unavailable due to system maintenance. Try again later. Quitting...") > QUIT >ENDIF >>
>** Timer event > >THIS.ENABLED = .F. >DO CASE > CASE m._lApplicationIsBusyProcessing = .T. > *!* application is busy with a process that should be > *!* detected as activity > m._tLastUseractivityDateTime = DATETIME() > m._nLastKeyPressedbyuser = 0 > m._cLastMousePosition = "0,0" > m._nWaiting2QuitCountdown = 0 > > CASE FILE(m._cAutoShutdownFlagFile) > *!* Someone has set a flag to signal autoshutdown for maintenance > *!* and is waiting until all users are out. > *!* start shutdown sequence > *!* provide warning that system is shutting down to allow user > *!* to close out of what they are doing, then quit > IF m._nWaiting2QuitCountdown >= m._nWaiting4UserToFinish > wait clear > QUIT && executes your "on shutdown" procedure and exits > ELSE > WAIT WINDOW "System maintenance is required. "+; > "Please complete all data entry and exit." NOWAIT NOCLEAR > m._nWaiting2QuitCountdown = m._nWaiting2QuitCountdown +1 > ENDIF > CASE m._nLastKeyPressedbyuser = LASTKEY() ; > AND m._cLastMousePosition = ; > ALLTRIM(STR(MROW()))+","+ALLTRIM(STR(MCOL())) > IF DATETIME()- m._tLastUseractivityDateTime ; > > m._nFormTimeoutInSeconds > *!* inactivity detected for too long > *!* begin shutdown sequence > QUIT && executes your on shutdown procedure and exits > > ENDIF >OTHERWISE > *!* keyboard activity or mouse activity detected - set activity variables > m._tLastUseractivityDateTime = DATETIME() > m._nLastKeyPressedbyuser = LASTKEY() > m._cLastMousePosition = = ALLTRIM(STR(MROW()))+","+ALLTRIM(STR(MCOL())) > m._nWaiting2QuitCountdown = 0 >ENDCASE > > >THIS.RESET >THIS.ENABLED = .T. >
DO WHILE .T. ME.Work() ENDDO