如何为检索Web数据创建时间循环

时间:2014-11-07 19:58:29

标签: vb.net visual-studio-2010 visual-studio

我使用

成功从网页检索数据
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://example.org")
MsgBox(result)

但是,我需要让它更新,就像每5分钟它应该再次检索数据。应该采用什么样的正确方法?感谢。

1 个答案:

答案 0 :(得分:1)

创建一个定时器设置处理程序并在每个间隔

中执行请求
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