Application Idlle Time out

luciliacoelho used Ask the Experts™
I would like, for security reasons, to disable an application use without a new login. I have a login screen on my application and I need to call it again after some (configurable) minutes.
How can I set up some iddle time function in order to make the users reintroduce their application's userid and password?
Is there any function or variable (Sys()) that can tell us which is the iddle time of an application (in this case the user is using a form)?
Kind regards
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
CaptainCyrilFounder, Software Engineer, Data Scientist

Create a timer function in your program. Let's say 20 minutes and it sets to the flag of logged in to false just like a session timeout in a web application.

When the user switches from one screen to another, you reset the timer or the LastAction variable.

Use the DATETIME() function and check for DATETIME()-LastAction > 20*60 && 20 minutes.
Following code calculates some figures which could tell how much time consumes Application in User mode and how much consumes in Kernel mode.

If the User time is zero (or near to zero) then user did nothing and you may handle the application as inactive. If the User time is higher than Kernel time then it means "User is doing something" or "Code is running".

You may test the code with   INKEY(10)  function which does not consume User time or with DO WHILE loop which consumes almost all User time. Differences are sugnificant.

In your real scenario the first part of the code should be executed at the app start and the second part in some timer which will calculate the inactivity time and decides about the login form execution. If there was some User activity detected then you just store values obtained in a timer to the initial values and then you may wait for the next Time event.

The code is provided "as is" and you would need some updates to it. Look for declared function names on the internet and update it in a way you need.


DECLARE integer GetSystemTimes IN kernel32.dll string @, string @, string @
DECLARE integer GetProcessTimes IN kernel32.dll integer, string @, string @, string @, string @
DECLARE integer GetCurrentProcess IN kernel32.dll

t1 = SECONDS()
a1 = repl(CHR(0),8)
b1 = repl(CHR(0),8)
c1 = repl(CHR(0),8)
pc1 = repl(CHR(0),8)
pe1 = repl(CHR(0),8)
pk1 = repl(CHR(0),8)
pu1 = repl(CHR(0),8)

?? GetSystemTimes(@a1,@b1,@c1)
?? GetProcessTimes(GetCurrentProcess(), @pc1, @pe1, @pk1, @pu1)
a1 = str2bi(a1)
b1 = str2bi(b1)
c1 = str2bi(c1)
pc1 = str2bi(pc1)
pe1 = str2bi(pe1)
pk1 = str2bi(pk1)
pu1 = str2bi(pu1)

*-- This process is measured:



t2 = SECONDS()
a2 = repl(CHR(0),8)
b2 = repl(CHR(0),8)
c2 = repl(CHR(0),8)
pc2 = repl(CHR(0),8)
pe2 = repl(CHR(0),8)
pk2 = repl(CHR(0),8)
pu2 = repl(CHR(0),8)

? GetSystemTimes(@a2,@b2,@c2)
?? GetProcessTimes(GetCurrentProcess(), @pc2, @pe2, @pk2, @pu2)
a2 = str2bi(a2)
b2 = str2bi(b2)
c2 = str2bi(c2)
pc2 = str2bi(pc2)
pe2 = str2bi(pe2)
pk2 = str2bi(pk2)
pu2 = str2bi(pu2)

st = (b2-b1)+(c2-c1)

? "Waiting period: ", t2-t1, "s"
? "CPU usage %: ", (st-(a2-a1))/st*100
? a1,a2,TRANSFORM(a2-a1), "Idle"
? b1,b2,TRANSFORM(b2-b1), "Kernel"
? c1,c2,TRANSFORM(c2-c1), "User"
? pc1, pc2, "Process crea"
*? pe1, pe2, pe2-pe1, "Process exit"
? "Results:"
? pk2-pk1, "Process kernel time"
? pu2-pu1, "Process user time"


LOCAL lnOut, laPower256[8]
lnOut = 0
laPower256[1] = 1
laPower256[2] = 256
laPower256[3] = 256*256
laPower256[4] = 256*256*256
laPower256[5] = 256*256*256*256
laPower256[6] = 256*256*256*256*256
laPower256[7] = 256*256*256*256*256*256
laPower256[8] = 256*256*256*256*256*256*256

FOR lnI = 1 TO 8
  lnOut = lnOut + ASC(SUBSTR(lcString, lnI, 1))*laPower256[lnI]


Open in new window

Olaf DoschkeSoftware Developer

You can use this code from a previous question.
...see the last comment from the OP, not only the answer accepted...

Bye, Olaf.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial