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
You'll need to use System.Threading.Thread.Sleep(number of milliseconds).
VB.net 4.0 framework Code :
Threading.Thread.Sleep(5000)
The integer is in miliseconds ( 1 sec = 1000 miliseconds)
I did test it and it works
I've had better results by checking the browsers readystate before continuing to the next step. This will do nothing until the browser is has a "complete" readystate
Make a timer, that activates whatever code you want to when it ticks. Make sure the first line in the timer's code is:
Replace timer with whatever you named your timer.
Then use this in your code:
I think this question is old but I provide another answer because it is useful fo others:
thread.sleep is not a good method for waiting, because usually it freezes the software until finishing its time, this function is better:
this function wait for specific time without freezing the software, however increases the CPU usage, but below function not only does not freeze the software, but also does not increase the CPU usage: