I am venturing into WPF – first time in (VB).NET – and trying to re-create a project I started in MS Access VBA. It basically scrapes a series of pages within a web application. As you may have surmised I am having trouble with the LoadCompleted event.
I have searched and found some information on it, but the “flow” of the code only lends itself to waiting for one page to load. For example:
http://social.msdn.microsoft.com/Forums/nn-NO/wpf/thread/52c1bc55-dd41-468c-8759-a42726635d4b
All of the code execution is run in the DocumentLoaded event which works fine when you just need to navigate to one page and execute code. But I need to perform a series of these cycles for my application.
How can I reliably wait for the document to fully load while still keeping the code execution in the same Sub AND not locking the UI thread?
Here’s a basic idea of what I’m trying to do.
- Navigate to page
- Wait for page to fully load
- do stuff
- Navigate to page
- Rinse, Repeat
P.S – .NET is very new to me so please don’t give my brain a stack overflow 😉
Thanks,
Brian
-## EDIT ##-
This is what I use to do in VBA. This is exactly what I’m trying to do, just in the “.NET” way and without blocking the UI Thread:
Dim oIE = New SHDocVw.InternetExplorer
With oIE
.Navigate(strURL)
.Visible = False
' loop until the page finishes loading
Do While oIE.Busy : Loop
Do While oIE.ReadyState <> 4 : Loop
'Code goes here to read DOM, get fields and click a button (logging in to site)
'My code execution is done and now I'm ready to go to the next page and read the DOM
.Navigate(strURL)
End With
.
.
.
.
That’s it. Repeat for n times. my interactions with each DOM are significantly different.
I would just call
Navigateagain at the end of theLoadCompletedhandler. Then, I guess, use a window-scoped variable to keep track of your target URLs.EDIT
Maybe something like this would be more suitable. After each cycle, you can set up the next URL as well as its handler.