ClaudeWalker
asked on
Timer instead of sleep vb.net
I am trying to have a program wait before execution however Threading.sleep does not allow execution while it's waiting.
I'm trying to set up a timer to pause execution but I'm unsure how to do it.
Thanks,
JOe K.
I'm trying to set up a timer to pause execution but I'm unsure how to do it.
Thanks,
JOe K.
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _
Handles WebBrowser1.DocumentCompleted
'MsgBox(cnt)
Dim t As Timer
t.Start() 'how can I use this to delay the subsequent
'lines of code. Lets say I want a 3 second delay to allow
'a page to fully load (including javascript which the event
'is not waiting for).
Dim MSDNpage As String = WebBrowser1.Document.Body.InnerText
My.Computer.FileSystem.WriteAllText("C:\Quib\" & cnt & ".txt", MSDNpage, False)
nextPage()
End Sub
ASKER
I tried it but it's not working because the sleep is halting all execution.
I think timer is the only way to go on this.
Thanks for the suggestion though
I think timer is the only way to go on this.
Thanks for the suggestion though
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@idle_Mind: I posted the entire method. The event is on DocumentComplete meaning when the HTML loads the event is run. However, it does not what for javascript to run. When I want to delay a a second for the javascript to run so when I scrape the screen I have the applicable data. I know a delay will work because when I add a msgbox the javascript loads if I wait a second and then renders properly (saved to .txt)
@VBClassicGuy: I tried Idle_Mind's method with no sleep. No joy.
@CodeCruiser: I tried the readystate but again that does not account for Javascript. The WebBrowser object thinks it's ready when the HTML is assembled.
Any ideas? The msgbox workaround works but I don't want to hit a msgbox 70 to 100 times.
Thanks,
JOe K.
@VBClassicGuy: I tried Idle_Mind's method with no sleep. No joy.
@CodeCruiser: I tried the readystate but again that does not account for Javascript. The WebBrowser object thinks it's ready when the HTML is assembled.
Any ideas? The msgbox workaround works but I don't want to hit a msgbox 70 to 100 times.
Thanks,
JOe K.
See if this helps
http://stackoverflow.com/questions/840813/how-to-use-webbrowser-control-documentcompleted-event-in-c
Also see if this extended webbrowser is any good
http://www.codeproject.com/KB/miscctrl/csEXWB.aspx
http://stackoverflow.com/questions/840813/how-to-use-webbrowser-control-documentcompleted-event-in-c
Also see if this extended webbrowser is any good
http://www.codeproject.com/KB/miscctrl/csEXWB.aspx
ASKER
I think I could do it if I multi-threaded the application vs the browser object.
Any ideas on how to do that?
I have posted my code below (I put it back into one recursive method).
Any ideas on how to do that?
I have posted my code below (I put it back into one recursive method).
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _
Handles WebBrowser1.DocumentCompleted
Dim MSDNpage As String = WebBrowser1.Document.Body.InnerText
My.Computer.FileSystem.WriteAllText("C:\Quib\" & cnt & ".txt", MSDNpage, False)
cnt += 1
If totalPages = 0 Then
totalPages = getTotalPages()
End If
Dim endTime As Date = Now.AddSeconds(3)
While (Now <= endTime)
Application.DoEvents()
End While
If cnt <> totalPages Then
WebBrowser1.Navigate("http://www.quibids.com/categories/Recently-Completed/" & cnt, False)
End If
End Sub
ASKER
GOT IT!
I used 4 webbrowsers letting each one load and then the object would check the previous one on document load (1 -> 4, 2 -> 1, 3 -> 2, 4 -> 3...)
I used 4 webbrowsers letting each one load and then the object would check the previous one on document load (1 -> 4, 2 -> 1, 3 -> 2, 4 -> 3...)
ASKER
Thanks for the direction.
-JOe K.
-JOe K.
Public Sub Delay(ByVal DelayInSeconds As Integer)
Dim ts As TimeSpan
Dim targetTime As DateTime = DateTime.Now.AddSeconds(De
Do
ts = targetTime.Subtract(DateTi
Application.DoEvents()
System.Threading.Thread.Sl
Loop While (ts.TotalSeconds > 0)
End Sub
Added to your code:
Private Sub WebBrowser1_DocumentComple
ByVal e As System.Windows.Forms.WebBr
Handles WebBrowser1.DocumentComple
Delay(3)
Dim MSDNpage As String = WebBrowser1.Document.Body.
My.Computer.FileSystem.Wri
nextPage()
End Sub