>Hi all,
>
>Is there a simple way to invoke an app timeout that will close an app after a predetermined amount of inactivity. I have an important update routine that runs in the middle of the evening, but will fail if a user of the app forgets to logout. Thanks for any ideas!
>
>John.
I asked the same question a couple of weeks ago...this is what I came up with.
FUNCTION TIMEOUT
_SCREEN.ADDOBJECT('otimeout','tmrtimeout')
_SCREEN.otimeout.INTERVAL = 150000*5 && 5 minutes = 150000
RETURN
**************************************************
*-- Class: tmrtimeout
*-- ParentClass: timer
*-- BaseClass: timer
*
DEFINE CLASS tmrtimeout AS TIMER
HEIGHT = 23
WIDTH = 23
*-- The amount of time to timeout on
ntimeout = 0
*-- Time this program last ran (in seconds)
nlastrun = 0
*-- Time the program detected the last change in state
nlastchange = 0
*-- Last mouse column detected
nlastmousecol = 0
*-- Last mouse row detected
nlastmouserow = 0
*-- Current mouse column
nmousecol = 0
*-- Current Mouse Row
nmouserow = 0
*-- Current Time the timer ran in calctime() format
nrun = 0
*-- Current active form.
cactiveform = ("")
*-- Active form at the last timer run
clastactiveform = ("")
*-- Value of LastKey() when timer is run.
nkey = 0
*-- Lastkey pressed by the user at the previous timer run.
nlastkey = 0
NAME = "tmrtimeout"
*-- Calculates time in seconds. Not the SECONDS() function.
PROCEDURE calctime
LPARAMETERS tcTime
IF PCOUNT() =0
tcTime = TIME()
ENDIF
#DEFINE SECONDS_DAY 86400
#DEFINE SECONDS_HOUR 3600
#DEFINE SECONDS_MINUTE 60
#DEFINE ELAPASED_DAYS DATE() - {01/01/97}
#DEFINE ELAPSED_HOURS
*-- This function will return seconds since 1/1/97. This way, when we move from
*-- one day to another (which would cause Seconds() to recycle to 0), we are
*-- not affected.
*--
*-- One other point. I am trying to optimize the code as much as possible because this
*-- timer may run many times in a session and I want it to be unnoticeable.
LOCAL lnDays, lnHours, lnMinutes, lnSeconds, lnRetVal
lnDays = DATE() - {01/01/97}
lnHours = VAL(LEFT(tcTime,2))
lnMinutes = VAL(SUBST(tcTime,4,2))
lnSeconds = VAL(SUBST(tcTime,7))
lnRetVal = (lnDays * SECONDS_DAY) + ;
(lnHours * SECONDS_HOUR) + ;
(lnMinutes * SECONDS_MINUTE) + ;
lnSeconds
RETURN lnRetVal
ENDPROC
*-- Timeout the application
PROCEDURE timeoutapp
goProgram.OnQuit
ENDPROC
PROCEDURE TIMER
LOCAL llChange, lnInterval
WITH THIS
*-- Turn the timer off while we are in the timer event
lnInterval= .INTERVAL
.INTERVAL = 0
.nrun = .calctime()
.nmousecol = MCOL("")
.nmouserow = MROW("")
.nkey = LASTKEY()
.cactiveform = IIF(TYPE("_screen.activeform.caption") == "C", ;
_SCREEN.ACTIVEFORM.CAPTION, ;
"***DESKTOP***")
llChange = !(.nkey = .nlastkey ;
AND .nmousecol = .nlastmousecol ;
AND .nmouserow = .nlastmouserow ;
AND .cactiveform == .clastactiveform)
*-- Now, if we have a change, just record it and go on
IF llChange
.nlastchange = .nrun
ELSE
IF .nrun - .nlastchange >= .ntimeout
IF BETWEEN(TIME(),'00:00:00','07:00:00') OR BETWEEN(TIME(),'18:15:00','23:59:59')
*-- Timeout
.timeoutapp()
ENDIF
ENDIF
ENDIF
*-- Save the current state
.nlastrun = .nrun
.nlastmousecol = .nmousecol
.nlastmouserow = .nmouserow
.nlastkey = .nkey
.clastactiveform = .cactiveform
*-- And that's that
.INTERVAL = lnInterval
ENDWITH
ENDPROC
ENDDEFINE
*
*-- EndDefine: tmrtimeout
**************************************************
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only