Reputation: 33
I have a program that is works fine one minute but as soon as my internet connection slows it stops working.
This is because I have everything set by timers.
I have tried slowing the intervals and still it messes up from time to time.
There must be a way for the program to wait until it has completed one task and then automatically carry out the next task instead of hooking the next task up to a timer.
Here is an example of what I mean:
WebBrowser1.navigate("http://www.google.com")
[IF COMPLETED THEN MOVE ON TO NEXT TASK]
WebBrowser1.Document.GetElementById("gbqfba").InvokeMember("click")
I'm pulling my hair out trying to work it figure it out lol
Upvotes: 0
Views: 1306
Reputation: 1
Threading.Thread.Sleep(1000) ' 1000 milliseconds is 1 second
Looking at your code, why not use the events?
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
WebBrowser1.Document.GetElementById("gbqfba").InvokeMember("click")
End Sub
Upvotes: 0
Reputation: 54417
The code in that method should end at the Navigate
call. When the WebBrowser
has finished loading the specified page, it will raise its DocumentCompleted
event. You handle that event and process the page in the event handler. You can then call Navigate
to load the next page and the process continues. By handling the event you don't have to care how long it takes to load the page. you know that you'll process it the moment it is loaded; not sooner, not later.
Upvotes: 1