无限LOOP /重复脚本?

时间:2013-03-31 21:29:58

标签: vb.net loops browser refresh

我在Visual Basic中有一个脚本,我似乎无法重复/循环。我希望在单击给定的变量,然后页面刷新后重复脚本。然后页面刷新并且刻度线为0,但是我希望脚本重复一遍(INFINITE)。这是我正在处理的脚本:

Private Sub Timer1_Tick(ByVal sender As System.Object,
                        ByVal e As System.EventArgs) Handles Timer1.Tick
  If Not number_of_ticks > 100 Then
    number_of_ticks += 1
    WebBrowser1.Document.GetElementById("claimIt").InvokeMember("Click")
  Else
    'number_of_ticks has exceed the maximum amount of allowed ticks
    Timer1.Enabled = False
    WebBrowser1.Refresh()
    number_of_ticks = 0
  End If
End Sub

但是当我尝试做一个LOOP时,它不起作用,程序变得没有响应:

Private Sub Timer1_Tick(ByVal sender As System.Object,
                        ByVal e As System.EventArgs) Handles Timer1.Tick
  Do
    If Not number_of_ticks > 100 Then
      number_of_ticks += 1
      WebBrowser1.Document.GetElementById("claimIt").InvokeMember("Click")
    Else
      'number_of_ticks has exceed the maximum amount of allowed ticks
      Timer1.Enabled = False
      WebBrowser1.Refresh()
      number_of_ticks = 0
    End If
  Loop
End Sub

我不知道为什么会这样,有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

您的Do-Loop会导致程序永久停滞。也许您应该在方法中重新启用计时器:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If Not number_of_ticks > 100 And Not WebBrowser1.IsBusy Then
        number_of_ticks += 1
        WebBrowser1.Document.GetElementById("claimIt").InvokeMember("Click")
    Else
        'number_of_ticks has exceed the maximum amount of allowed ticks
        Timer1.Enabled = False
        WebBrowser1.Refresh()
        number_of_ticks = 0

        ' re-enable the timer to repeat again
        Timer1.Enabled = True
    End If
End Sub