0

I am successfully retrieving the data from webpage by using

Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://example.org")
MsgBox(result)

However, I need to make it updating, like every 5 minutes it should retrieve the data again. What is the correct approach should be ? Thanks.

pedrommuller
  • 15,741
  • 10
  • 76
  • 126
user198989
  • 4,574
  • 19
  • 66
  • 95
  • 2
    using a timer object or control is probably your best solution, just search c# timer and then in the timer_elapsed event you could pull the data. – Kevin Nov 07 '14 at 20:01
  • @Kevin Answers should be posted as answers, not comments. – BlueMonkMN Nov 07 '14 at 20:06
  • 1
    It looks more like a suggestion. Answers should be more detailed. I think thats what he thought, and he is correct. – user198989 Nov 07 '14 at 20:11
  • 1
    If it's going to run for a long time, you may want to think about a Windows service. – Tim Nov 07 '14 at 20:12
  • 1
    Regarding timers, might wanna check this out : http://stackoverflow.com/questions/1416803/system-timers-timer-vs-system-threading-timer – Victor Zakharov Nov 07 '14 at 20:14

1 Answers1

1

create a timer set a handler and do the request in every interval

Imports System.Timers
Public Class TimerRequest
    Private Shared aTimer As Timer
    Private Shared o as Object
        Public Shared Sub Main()
             aTimer = New System.Timers.Timer(300000) ' 5 minutes
             AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
             aTimer.Enabled = True
        End Sub  
        Private Shared Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
            o = CreateObject("InternetExplorer.Application") 
            Dim webClient As New System.Net.WebClient
            Dim result As String = webClient.DownloadString("http://example.org")
            For i As Integer = 0 To 2
                //your loop here
            Next
        End Sub  
 End Class  
pedrommuller
  • 15,741
  • 10
  • 76
  • 126