timer function

  • Thread starter Thread starter TJS
  • Start date Start date
T

TJS

looking for example of timer function

something that will help me get to track user's elapsed time since last
refresh.

tried this but not working with session values correctly in my class

================================================================
Function NewText() As String

Dim vString As String=" "
Dim dtm As DateTime
dtm = DateTime.Now()

If context.session("ScreenTimer") is nothing Then
context.session("ScreenTimer") = Hour(dtm) * 60 + Minute(dtm)
else
context.session("TimeElapsed") = Hour(dtm) * 60 + Minute(dtm) -
cDBL(context.session("ScreenTimer"))
end if

If context.session("TimeElapsed") > 1 Then
vString= "new text here"
context.session("ScreenTimer") = Hour(dtm) * 60 + Minute(dtm)
End If
return vString
End Function
 
Hi,

This look pretty complicated :-)
Why don't you just store the DateTime directly in to Session?
Code is C#, but I think you get the idea...


store in session
****************

//store initial value:
Context.Session.Add("LastAccess", DateTime.Now);


get elapsed time
****************

//get time passed:
DateTime lastAccess = (DateTime)Session["LastAccess"];

//get the elapsed time
TimeSpan difference = DateTime.Now.Subtract(lastAccess);


hth, Philipp
 
Back
Top