0

I'm doing these webrequests loops and I need to keep track of time (unix time) elapsed since first request. For ex:

    Dim post1 String = "http://www.xxx.com/......" & UnixTimeNow1stCall & "......"
    Dim postReq1 As HttpWebRequest = DirectCast(WebRequest.Create(post1), HttpWebRequest)

    Dim post2 String = "http://www.xxx.com/......" & UnixTimeElasped1stCall& "......"
    Dim postReq2 As HttpWebRequest = DirectCast(WebRequest.Create(post2), HttpWebRequest)


    Dim post3 String = "http://www.xxx.com/......" & UnixTimeElasped1stCall& "......"
    Dim postReq3 As HttpWebRequest = DirectCast(WebRequest.Create(post3), HttpWebRequest)

*LOOP again*

And so on. In other words, I need to lock the current Unix Time in the first call and whenever I call later (in spaces of 10 seconds), I need it to reference this first call.

Using this to calculate current Unix time:

Public Function UnixNow() As Long

    Dim _TimeSpan As TimeSpan = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0))

    Return CLng(_TimeSpan.TotalSeconds)

End Function

Whenever I call UnixTime is giving me the current time, so result is always 0. Any hints?

Vandelay
  • 3
  • 2
  • I'd suggest using `example.com` for example domain names instead of otherwise registered domains of questionable content. – Joey Jun 29 '12 at 06:30
  • You're correct, Joey. I totally forgot about that. I'll use example.com from now on :) – Vandelay Jun 29 '12 at 07:17

1 Answers1

0

Of course UnixNow will always give you the current time...

Store it and compute the difference

Dim unixTimeFirstRequest Long = UnixNow()
Dim post1 String = "http://www.xxx.com/......" & unixTimeFirstRequest & "......"
Dim postReq1 As HttpWebRequest = DirectCast(WebRequest.Create(post1), HttpWebRequest)

Dim post2 String = "http://www.xxx.com/......" & UnixNow() - unixTimeFirstRequest & "......"
Dim postReq2 As HttpWebRequest = DirectCast(WebRequest.Create(post2), HttpWebRequest)


Dim post3 String = "http://www.xxx.com/......" & UnixNow() - unixTimeFirstRequest & "......"
Dim postReq3 As HttpWebRequest = DirectCast(WebRequest.Create(post3), HttpWebRequest)
  • Thanks for your reply, but didn't work, still gives me 0 as response. It seems so simple, but I just can't figure it out. – Vandelay Jun 29 '12 at 06:12
  • Sorry, got the question wrong. The UnixNow() code works totally fine on my system. – R.Müller Jun 29 '12 at 07:40