Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Quiting application when idle
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00951380
Message ID:
00953304
Views:
14
I guess you could find an external desktop applet or write one that checks if your application is active, checks for key and mouse activity and CPU utilization that kills the process when certain idle conditions are met. Do you not have a way to instantiate a timer or create an application object from the application?



>I don't have acces to the main program, eventhough your ideas guys are good, i ma mopre interested in one timer maybe or a desktop event that takes cares of the idleness.
>
>
>
>>>I need to kick the users out when they've being idle for some period of time, I know this could be simple but don't know how to do it. specially because you have to take in count that we're using sql server and an odbc conneccion to it, so i want to be sure that the sql server is not working on the background making some large query, then i don't want to kick the user out.
>>>
>>>but if it is idle and is not perfoming a sql query in the server, then I want to kcik him out
>>
>>I use a timer and some application global variables initially declared private in my main procedure. The variables to keep track of activity or lack of activity. The timer is used to set these variables and check for activity and shutdown the application when inactivity is detected beyond a specified time period. This timer is also used to detect when someone needs to do maintenance that requires everyone to be out and shuts down for maintenance. The following is just an example of how you can do this (not tested)
>>
>>
>>*!* 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
>>
>>
>>
>>
>>
>>In the timer event set to fire every x number of seconds to check activity.
>>
>>
>>** 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.
>>
Previous
Reply
Map
View

Click here to load this message in the networking platform