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();\",\"JavaSc
The suggested Code is flawed:
Imports VB = Microsoft.VisualBasic
Public Sub wait(ByVal seconds As Single)
Static start As Single
start = VB.Timer()
Do While VB.Timer() < start + seconds
System.Windows.Forms.Application.DoEvents()
Loop
End Sub
VB.Timer() returns the seconds since midnight. If this is called just before midnight the break will be nearly a full day. I would suggest the following:
Private Sub Wait(ByVal Seconds As Double, Optional ByRef BreakCondition As Boolean = False)
Dim l_WaitUntil As Date
l_WaitUntil = Now.AddSeconds(Seconds)
Do Until Now > l_WaitUntil
If BreakCondition Then Exit Do
DoEvents()
Loop
End Sub
BreakCondition can be set to true when the waitloop should be cancelled as DoEvents is called this can be done from outside the loop.