timer function

Discussion in 'ASP .Net' started by TJS, Nov 7, 2004.

  1. TJS

    TJS Guest

    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
    TJS, Nov 7, 2004
    #1
    1. Advertising

  2. TJS

    Philipp Sumi Guest

    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



    TJS wrote:

    > 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
    >
    >
    Philipp Sumi, Nov 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. H @ Q
    Replies:
    0
    Views:
    452
    H @ Q
    May 31, 2004
  2. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    707
    Kelsang Wangchuk
    Jul 31, 2003
  3. Replies:
    1
    Views:
    1,580
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  4. Simon

    page timer, or redirect timer

    Simon, Nov 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,188
    Bruce Barker
    Nov 4, 2005
  5. Replies:
    8
    Views:
    481
    Jorgen Grahn
    Jul 15, 2013
Loading...

Share This Page