【问题标题】:Infinite LOOP/Repeat script?无限循环/重复脚本?
【发布时间】:2013-03-22 00:19:57
【问题描述】:

我在 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

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

【问题讨论】:

    标签: vb.net loops browser refresh


    【解决方案1】:

    您的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
    

    【讨论】:

    • 啊,我认为这会奏效,但有一个问题:gyazo.com/2a6935adecafffe3f4628fe899c7cd28 我认为这个问题的意思是它试图在页面完全刷新之前返回点击。所以我想我需要放置一个 IF WebBrowser is Loaded THEN enable Timer1,但我对 VB 还很陌生,我想知道如何在 IF 语句中放置一个 IF?
    • @JackC。 - 我没有对浏览器控件做很多事情,所以我的编辑可能不适合你。 IsBusy 标志告诉您浏览器是否仍在加载文件,并且可能在这里用作检查。我在第一个 If 语句中添加了对 IsBusy 的检查。
    • 感谢朋友的帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-06
    • 2014-03-09
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 2011-03-31
    • 2013-12-24
    相关资源
    最近更新 更多