🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
5 messages
5 total messages Started by Tom Mon, 29 Jan 2007 13:40
How to properly wait for TCPPWebbrowser to be ready...
#1397
Author: Tom
Date: Mon, 29 Jan 2007 13:40
36 lines
2013 bytes
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...
#1400
Author: Remy Lebeau (TeamB)
Date: Mon, 29 Jan 2007 18:46
40 lines
2446 bytes
"Tom" <tom@nospam.net> wrote in message
news:45bdf8f5$1@newsgroups.borland.com...

> 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.

> 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.

> 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.

> 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...
#1407
Author: Tom
Date: Tue, 30 Jan 2007 01:11
40 lines
2454 bytes
Remy,

> 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.

> 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.

> 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.


> 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.

> 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
Re: How to properly wait for TCPPWebbrowser to be ready...
#1408
Author: Remy Lebeau (TeamB)
Date: Tue, 30 Jan 2007 20:26
15 lines
1597 bytes
"Tom" <tom@nospam.net> wrote in message
news:45be9aed$1@newsgroups.borland.com...

> 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...
#1410
Author: Tom
Date: Wed, 31 Jan 2007 05:12
10 lines
1482 bytes
> 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads