I’d like to ‘sense’ if a user is actually working in an open web page (web app), and if they’re idle for X amount of time send them back to login_page.Show()
What has the least overhead way for measuring active interaction(s) from a user, to see if they’ve abandoned the app/page?
Here’s a little thing I wrote - if you have an Admin WebPage, this code in a timer will update a textArea showing a list of the currently logged in users:
Sub Timer.Run() Handles Run
var onlineUsers() as string
var nSessions as integer = app.SessionCount
for each s as session in app.Sessions
onlineUsers.Append(s.Username + If(s.isDisconnected, "(x)", "") + _
+ " " + format(s.lifetimeSeconds, "#") + " seconds " _
+ if(s.currentPage = nil, " - (no page)", " - " + s.CurrentPage.Name ) )
next
lSessionInfo.Value = str(nSessions) + " sessions : " + EndOfLine + string.FromArray(onlineUsers,EndOfLine)
End Sub
Where lifetimeSeconds is a function on the Session object:
Public Function lifetimeSeconds() As double
// how many seconds has this session been alive
dim d as double = system.Microseconds
dim dt as double = d-createdMicroseconds
dim t as double = dt/1.0e6 // convert to seconds
return t
End Function
and createdMicroseconds is set in Session.Opening:
Sub Opening() Handles Opening
createdMicroseconds = system.Microseconds
End Sub
Just so everyone understands, if you want the user to stop consuming resources, you should either direct them away from the app to an html page with a link to come back or serve that page from HandleURL. Otherwise, the usertimeout code will run over and over every X seconds if the user walks away leaving your app open.
Thanks @Wayne_Golding and @Greg_O, good to know! I have a timer on the login page that does a redirect to a URL (away from the app), so if the user times out they can still log back in (and the state of the app and their data is still intact), or if like you said they walk away then it’s a final means of directing them away from the app and releasing resources. The best of both worlds!