Board index » cppbuilder » How to properly wait for TCPPWebbrowser to be ready...

How to properly wait for TCPPWebbrowser to be ready...


2007-01-29 09:40:03 PM
cppbuilder1
I've got everything working as it stands, however the program is
jumping to 99% cpu usage when it's waiting for the browser to
finish it's action. What I'd like to know, is how to wait without
being such a hog.
Here's the scenario:
I load up a web page, then using the IHTMLDocument3 I get
access to the controls I need by Id and modify them. When
that's done I use the click() function to submit the form.
The form is AJAX based, so I have to wait until that action is
completed before finally obtaining the source code from the
results div. In order to determine when to stop waiting I'm
checking the Style of another div to see if it's set back to hidden.
When the ajax portion is running the div is visible
(just says "Loading...please wait") and when it's not the div is
set to hidden.
So anyways, what I've got now for the loop is this:
WideString S;
do
{
TComInterface <IHTMLStyle>Style;
Element->get_style(&Style);
Style->get_display(&S);
}while(S == WideString(""));
I've also noticed the program appears to be locked up during this
loop. I added Application->ProcessMessages() to the loop but
that didn't help.
Thanks,
Tom
 
 

Re:How to properly wait for TCPPWebbrowser to be ready...

"Tom" < XXXX@XXXXX.COM >wrote in message
Quote
I've got everything working as it stands, however the program is
jumping to 99% cpu usage when it's waiting for the browser to
finish it's action.
That is because you are running a tight unyielding loop that doesn't
allow other threads to access the CPU.
Quote
What I'd like to know, is how to wait without being such a hog.
You need to call Application->ProcessMessages() periodically in your
loop. Maybe also Sleep() as well.
Also, your loop is checking for a blank "display" property, which may
not always be blank, even when the div disappears. It might be
getting set to "none" instead of "".
Amsuming the page is using an XMLHttpRequest object, you could try
hooking its onreadystatechange event, and then query its readystate
property when it changes to see when the tansmission is finished (or
just query the readystate in a loop instead of using an event). You
can also retrieve the data of the response, if needed.
Quote
I load up a web page, then using the IHTMLDocument3 I get
access to the controls I need by Id and modify them. When
that's done I use the click() function to submit the form.
The OnDocumentComplete event is the most ideal place for that logic.
Quote
I've also noticed the program appears to be locked up during this
loop.
Of course. Because you are not allowing any new messages to be
processed.
Gambit
 

Re:How to properly wait for TCPPWebbrowser to be ready...

Remy,
Quote
You need to call Application->ProcessMessages() periodically in your
loop. Maybe also Sleep() as well.
I tried this before posting and it didn't seem to have much of an effect. I
moved the code from my test app into the actual program and it doesn't
seem to lock up nearly as bad.
Quote
Also, your loop is checking for a blank "display" property, which may
not always be blank, even when the div disappears. It might be
getting set to "none" instead of "".
Correct, as soon as it's done loading display goes to none. That's why
I loop until it's set with something.
Quote
Amsuming the page is using an XMLHttpRequest object, you could try
hooking its onreadystatechange event, and then query its readystate
property when it changes to see when the tansmission is finished (or
just query the readystate in a loop instead of using an event). You
can also retrieve the data of the response, if needed.
Ah great, that's what I was hoping for. I'll give that a shot.
Quote
The OnDocumentComplete event is the most ideal place for that logic.
Correct, though the web page only gets loaded once, and then everything
else is updated via AJAX.
Quote
Of course. Because you are not allowing any new messages to be
processed.
True, but as I pointed out I did try to use
Application->ProcessMessages() without having much improvement.
I think the event you mentioned above will work fine.
Thanks!
-Tom
 

{smallsort}

Re:How to properly wait for TCPPWebbrowser to be ready...

"Tom" < XXXX@XXXXX.COM >wrote in message
Quote
as soon as it's done loading display goes to none. That's
why I loop until it's set with something.
That is not what I said. The display property could be returning the
actual string "none" instead of an empty string "" when the div
becomes hidden. In any case, you said you are looping to wait for the
div to hide, but that is not what your code is actually showing. You
are waiting for the div to obtain any kind of style at all.
Gambit
 

Re:How to properly wait for TCPPWebbrowser to be ready...

Quote
That is not what I said. The display property could be returning the
actual string "none" instead of an empty string "" when the div
becomes hidden. In any case, you said you are looping to wait for the
div to hide, but that is not what your code is actually showing. You
are waiting for the div to obtain any kind of style at all.
Correct, on this site the the display property is either blank or set
to none. I suppose I could update the code, to be exact =)
-Tom