How do I wait for a web page?

C

CedricCicada

I am developing a stock market simulator using data from Yahoo's
Finance page. I am using a web browser control hosted on a form that
has a public method named GetPage(), which takes a URL. I want
GetPage() to call m_browser.Navigate() and then wait for the
DocumentComplete event. The DocumentComplete event handler will store
the inner text of the body of the returned document and then wake up
GetPage(), which will then return the text to its caller.

I thought I could use a ManualResetEvent object named m_dataReceived to

manage this. After Navigate(), I call m_dataReceived.Reset() and then
m_dataReceived.WaitOne(). In the DocumentComplete event handler, I
call m_dataReceived.Set(). However, the event handler never runs. If
I take out the events and just let things happen when they want to, I
get the data from the web page.


What am I doing wrong?


Thank you very much.


Rob Richardson
 
M

Marcel Beutner

Hi Rob,
if you just want to wait till the page is loaded, you can use the
GetReadyState function. I do this under vc, because of this I'm not sure
whether it works for .net, too.

Here my code:

m_browser.Navigate(ASPX_FILE, NULL, NULL, NULL, NULL);


const int READYSTATE_COMPLETE = 4;
while(m_browser.GetReadyState() == READYSTATE_COMPLETE)
{
Sleep(10);
}

//Do somthing

Best Regards
Marcel
 
C

CedricCicada

Robson,

That looks great! I'm glad there's an easier way than I was trying!

Thank you very much!

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top