在继续代码 VB.net 之前等待 0.5 秒

问题描述:

我有一个代码,我希望它在继续之前在中间的某个地方等待.在 WebBrowser1.Document.Window.DomWindow.execscript("checkPasswordConfirm();","JavaScript") 之后我希望它等待 0.5 秒,然后执行其余代码.

I have a code and I want it to wait somewhere in the middle before going forward. After the WebBrowser1.Document.Window.DomWindow.execscript("checkPasswordConfirm();","JavaScript") I want it to wait .5 seconds and then do the rest of the code.

    WebBrowser1.Document.Window.DomWindow.execscript("checkPasswordConfirm();","JavaScript")

    Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
    For Each webpageelement As HtmlElement In allelements
        If webpageelement.InnerText = "Sign Up" Then
            webpageelement.InvokeMember("click")
        End If
    Next

您需要使用 System.Threading.Thread.Sleep(毫秒数).

WebBrowser1.Document.Window.DomWindow.execscript("checkPasswordConfirm();","JavaScript")

Threading.Thread.Sleep(500) ' 500 milliseconds = 0.5 seconds

Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
For Each webpageelement As HtmlElement In allelements
    If webpageelement.InnerText = "Sign Up" Then
        webpageelement.InvokeMember("click")
    End If
Next