tags:

views:

62

answers:

3

I am counting how many seconds it takes to go from aspx page 1 to page 2. This time is not reflecting a real clock.. Where is the bug?

on page 1 I have:

Session("sessioncreated") = Now.Ticks

on page 2 I have:

Dim diff As Long = 0
If Not Session("sessioncreated") Is Nothing Then
  diff = Now.Ticks - Session("sessioncreated")
End If
Dim timediff As Integer = TimeSpan.FromTicks(diff).Seconds
+3  A: 

It would help to know what issues you're seeying... Regardless, I think you should change:

Dim timediff As Integer = TimeSpan.FromTicks(diff).Seconds

to

Dim timediff As Integer = TimeSpan.FromTicks(diff).TotalSeconds
ARGH! How did I not see that. Good catch! That's my all time favorite .NET gotcha.
Jon B
+1  A: 

Use:-

Session("sessioncreated") = Now
Dim diff as TimeSpan

If Not Session("sessioncreated") Is Nothing Then
   diff = Now - DirectCast(Session("sessioncreated"), DateTime)
End If
Dim timediff As Integer = diff.TotalSeconds
AnthonyWJones
A: 

keep it simple

    Dim stpw As New Stopwatch 'declare in the class


    'on page 1
    stpw.Reset()
    stpw.Start()


    'on page 2
    stpw.Stop()
    'stpw.Elapsed.TotalSeconds 'will contain seconds between the two
dbasnett