0

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

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

但是当我尝试做一个循环时,它不起作用,程序变得无响应:

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

我不知道为什么会发生这种情况,有什么帮助吗?

4

1 回答 1

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
于 2013-03-31T22:06:41.403 回答