Thank you for the assistance. I was running my code from invisde a seperate
thread from the main application so that the window would be automatically
redrawn and this appears to have been causing the problems. Now I run it all
in the same thread and simply use the following function to load a page and
wait until it is fully loaded:
protected HTMLDocument GotoPage(string URL)
{
while (webAccess.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
{
System.Windows.Forms.Application.DoEvents();
System.Threading.Thread.Sleep(250);
}
webAccess.Navigate(URL);
while (webAccess.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
{
System.Windows.Forms.Application.DoEvents();
System.Threading.Thread.Sleep(250);
}
return (HTMLDocument)(webAccess.Document);
}
Thank you again for all of your help :)
"Chris Priede" <pr****@panix.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
David Pendrey wrote: Thanks, that code is working better but still not well enough
unfortunatly. I've fiddled around a bit and your code works fine when
it's in the code being pressed by a button after you press a button
to load the page. However if you have code to go to a page, then
sleep until ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
and then use your code it doesn't work. I tried to wait a while (up
to 5 seconds) and running your code in a seperate thread with no
luck. Any ideas on this?
My project was an automated sequence of about half a dozen steps, which
logs in to a site with a username/password, navigates to a specific page,
submits a search form on that page, and scrubs data from the results. The
sequence is driven by a timer and a state machine. Completion, timeout
and errors are detected through DocumentComplete and NavigateError events.
This might not be the greatest design, but it seems to work well enough
under both normal and error circumstances.
I never attempted to use ReadyState to detect completion. This is not to
say it wouldn't work, though.
If you use a separate thread, make sure you are using Invoke/BeginInvoke
for anything having to do with the browser control. It also appears
necessary to do so within any handlers for the browser control's events.
--
Chris Priede