Easiest way to sense "actively using" (vs. "idle") in Web App

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?

What about the WebSession.UserTimeout property? When set, the WebSession.UserTimedOut Event will occur letting you know they’re idle.

1 Like

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

Thanks @Tim_Parnell it really boiled down to (2) simple entries (thanks!):

// Put this in Session.Opening(): Self.UserTimeout = 60 'put a reasonable time here

// Put this in Session.UserTimedOut(): Self.login_page.Show() 'and do other log-out functions as well