do I need a "pause" before loading a new page with mshtml?

  • Thread starter Thread starter trint
  • Start date Start date
T

trint

if I have a "break;" before this:

mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;

it loads a new page as I want it to:

break;

case 3:
mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;

but if I just have it in the middle of a function, it doesn't change
from the last page.

Any help is appreciated.
Thanks,
Trint
 
if I have a "break;" before this:

mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;

it loads a new page as I want it to:

break;

case 3:
mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;

but if I just have it in the middle of a function, it doesn't change
from the last page.

A break-statement is not a "pause" of any sort. It's used to break out
of loops and switch-statement.

If you post the actual code snippets which do and do not work, and
detail the symptoms of what you see, we may be able to help.

One thing that is worth remembering at all times when working with
MSHTML in general is that all load operations are asynchronous. In
other words, when you ask it to load a page, you should not expect to
see that page in the control (or obtainable via its properties) in the
next line of code. If you're using the WinForms WebBrowser control,
you should handle DocumentCompleted event. If you're using MSHTML
directly, you have to look at its documentation to determine what is
the analog there - I do not recall it, but I believe it had something
to do with readyState property, which is set to "complete" upon
completion.
 
if I have a "break;" before this:

mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;

it loads a new page as I want it to:

break;

case 3:
mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;

but if I just have it in the middle of a function, it doesn't change
from the last page.

A break-statement is not a "pause" of any sort. It's used to break out
of loops and switch-statement.

If you post the actual code snippets which do and do not work, and
detail the symptoms of what you see, we may be able to help.

One thing that is worth remembering at all times when working with
MSHTML in general is that all load operations are asynchronous. In
other words, when you ask it to load a page, you should not expect to
see that page in the control (or obtainable via its properties) in the
next line of code. If you're using the WinForms WebBrowser control,
you should handle DocumentCompleted event. If you're using MSHTML
directly, you have to look at its documentation to determine what is
the analog there - I do not recall it, but I believe it had something
to do with readyState property, which is set to "complete" upon
completion.
 
A break-statement is not a "pause" of any sort. It's used to break out
of loops and switch-statement.

If you post the actual code  snippets which do and do not work, and
detail the symptoms of what you see, we may be able to help.

One thing that is worth remembering at all times when working with
MSHTML in general is that all load operations are asynchronous. In
other words, when you ask it to load a page, you should not expect to
see that page in the control (or obtainable via its properties) in the
next line of code. If you're using the WinForms WebBrowser control,
you should handle DocumentCompleted event. If you're using MSHTML
directly, you have to look at its documentation to determine what is
the analog there - I do not recall it, but I believe it had something
to do with readyState property, which is set to "complete" upon
completion.

here is the code that is keeping the previous webpage instead of the
new one that is being called (in other words, it isn't changing to the
new website that is in the string array below):

object loc2 = strArrayWWWcargoShipNamesCleaned1[cc]; <--the new
website is in here, but isn't being brought up by the following code
(contains last website).
object null_obj_str2 = "";
System.Object null_obj2 = 0;
this.axWebBrowser1.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);

mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;
//MessageBox.Show(doc2.documentElement.innerHTML);

StringBuilder sb2 = new StringBuilder();

sb2.Append(doc4.documentElement.innerHTML);
str2 = string.Empty;
str2 = sb2.ToString();

thanks,
Trint
 
A break-statement is not a "pause" of any sort. It's used to break out
of loops and switch-statement.

If you post the actual code  snippets which do and do not work, and
detail the symptoms of what you see, we may be able to help.

One thing that is worth remembering at all times when working with
MSHTML in general is that all load operations are asynchronous. In
other words, when you ask it to load a page, you should not expect to
see that page in the control (or obtainable via its properties) in the
next line of code. If you're using the WinForms WebBrowser control,
you should handle DocumentCompleted event. If you're using MSHTML
directly, you have to look at its documentation to determine what is
the analog there - I do not recall it, but I believe it had something
to do with readyState property, which is set to "complete" upon
completion.

here is the code that is keeping the previous webpage instead of the
new one that is being called (in other words, it isn't changing to the
new website that is in the string array below):

object loc2 = strArrayWWWcargoShipNamesCleaned1[cc]; <--the new
website is in here, but isn't being brought up by the following code
(contains last website).
object null_obj_str2 = "";
System.Object null_obj2 = 0;
this.axWebBrowser1.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);

mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;
//MessageBox.Show(doc2.documentElement.innerHTML);

StringBuilder sb2 = new StringBuilder();

sb2.Append(doc4.documentElement.innerHTML);
str2 = string.Empty;
str2 = sb2.ToString();

thanks,
Trint
 
here is the code that is keeping the previous webpage instead of the
new one that is being called (in other words, it isn't changing to the
new website that is in the string array below): [...]

Here are some links you may find helpful:http://www.yoda.arachsys.com/csharp.../csharp/incomplete.htmlhttp://sscce.org/(some Java-centric stuff, but mostly applicable to any  
programming questions)

I just want to somehow loop this until all of the "contact" pages that
are loaded and the emails are gathered successfully, but I can't get
to the second website that is in the array
strArrayWWWcargoShipNamesCleaned1[cc]. The first one works fine...I
just want all of them
to work the same way...Here is the code I have so far and any help or
insight is much appreciated:

mshtml.HTMLDocumentClass doc2 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;
//MessageBox.Show(doc2.documentElement.innerHTML);

StringBuilder sb2 = new StringBuilder();
string str2 = "";

sb2.Append(doc2.documentElement.innerHTML);

str2 = sb2.ToString();

Regex exp2 = new Regex(@"(?<=href="")[^""]+contact
[^""]+", RegexOptions.IgnoreCase);
MatchCollection collection2 = exp2.Matches(str2);

if (collection2.Count > 0)
{

string testString1 = string.Empty;

foreach (Match match2 in collection2)
{
//do something here
GroupCollection groups = match2.Groups;

testString1 = string.Format("{1}", groups
["word"].Value, groups[0].Value, groups[1].Value);
}

object loc3 = strArrayWWWcargoShipNamesCleaned1
[cc] + testString1;
object null_obj_str3 = "";
System.Object null_obj3 = 0;
this.axWebBrowser1.Navigate2(ref loc3, ref
null_obj3, ref null_obj3, ref null_obj_str3, ref null_obj_str3);

Task++;

cc++;

//getEmailAgain_Load();
break;

}
else
{
//found no contact page, so do this...
Task = 3;

}
break;

case 4:

mshtml.HTMLDocumentClass doc3 =
(mshtml.HTMLDocumentClass)this.axWebBrowser1.Document;
//MessageBox.Show(doc3.documentElement.innerHTML);

StringBuilder sb3 = new StringBuilder();
//string str3 = "";

sb3.Append(doc3.documentElement.innerHTML);
str3 = sb3.ToString();

Regex exp3 = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w
+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase);

MatchCollection collection3 = exp3.Matches(str3);

if (collection3.Count > 0)
{
//testString3[] = Array.Clear;

int thisInt = 0;
foreach (Match match3 in collection3)
{
//do something here
GroupCollection groups = match3.Groups;

testString3[thisInt] = string.Format
("{1}", groups["word"].Value, groups[0].Value, groups[1].Value);
thisInt++;
//write out emails here to db or text...
}

//save the email and
//continue on to the next companies website...

//Task = 3;
//Close();
//Task++;

//getNextCompanysContactHTML();

break;

}
else
{
//found no emails, so do this...

//Task = 3;

}

break;

Thanks,
Trint
 
here is the code that is keeping the previous webpage instead of the
new one that is being called (in other words, it isn't changing to the
new website that is in the string array below): [...]

Here are some links you may find helpful:http://www.yoda.arachsys.com/csharp.../csharp/incomplete.htmlhttp://sscce.org/(some Java-centric stuff, but mostly applicable to any  
programming questions)

I just want to somehow loop this until all of the "contact" pages that
are loaded and the emails are gathered successfully, but I can't get
to the second website that is in the array
strArrayWWWcargoShipNamesCleaned1[cc]. The first one works fine...I
just want all of them
to work the same way...Here is the code I have so far and any help or
insight is much appreciated:

mshtml.HTMLDocumentClass doc2 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;
//MessageBox.Show(doc2.documentElement.innerHTML);

StringBuilder sb2 = new StringBuilder();
string str2 = "";

sb2.Append(doc2.documentElement.innerHTML);

str2 = sb2.ToString();

Regex exp2 = new Regex(@"(?<=href="")[^""]+contact
[^""]+", RegexOptions.IgnoreCase);
MatchCollection collection2 = exp2.Matches(str2);

if (collection2.Count > 0)
{

string testString1 = string.Empty;

foreach (Match match2 in collection2)
{
//do something here
GroupCollection groups = match2.Groups;

testString1 = string.Format("{1}", groups
["word"].Value, groups[0].Value, groups[1].Value);
}

object loc3 = strArrayWWWcargoShipNamesCleaned1
[cc] + testString1;
object null_obj_str3 = "";
System.Object null_obj3 = 0;
this.axWebBrowser1.Navigate2(ref loc3, ref
null_obj3, ref null_obj3, ref null_obj_str3, ref null_obj_str3);

Task++;

cc++;

//getEmailAgain_Load();
break;

}
else
{
//found no contact page, so do this...
Task = 3;

}
break;

case 4:

mshtml.HTMLDocumentClass doc3 =
(mshtml.HTMLDocumentClass)this.axWebBrowser1.Document;
//MessageBox.Show(doc3.documentElement.innerHTML);

StringBuilder sb3 = new StringBuilder();
//string str3 = "";

sb3.Append(doc3.documentElement.innerHTML);
str3 = sb3.ToString();

Regex exp3 = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w
+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase);

MatchCollection collection3 = exp3.Matches(str3);

if (collection3.Count > 0)
{
//testString3[] = Array.Clear;

int thisInt = 0;
foreach (Match match3 in collection3)
{
//do something here
GroupCollection groups = match3.Groups;

testString3[thisInt] = string.Format
("{1}", groups["word"].Value, groups[0].Value, groups[1].Value);
thisInt++;
//write out emails here to db or text...
}

//save the email and
//continue on to the next companies website...

//Task = 3;
//Close();
//Task++;

//getNextCompanysContactHTML();

break;

}
else
{
//found no emails, so do this...

//Task = 3;

}

break;

Thanks,
Trint
 
One thing that is worth remembering at all times when working with
MSHTML in general is that all load operations are asynchronous. In
other words, when you ask it to load a page, you should not expect to
see that page in the control (or obtainable via its properties) in the
next line of code. If you're using the WinForms WebBrowser control,
you should handle DocumentCompleted event. If you're using MSHTML
directly, you have to look at its documentation to determine what is
the analog there - I do not recall it, but I believe it had something
to do with readyState property, which is set to "complete" upon
completion.

here is the code that is keeping the previous webpage instead of the
new one that is being called (in other words, it isn't changing to the
new website that is in the string array below):

object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];  <--the new
website is in here, but isn't being brought up by the following code
(contains last website).
            object null_obj_str2 = "";
            System.Object null_obj2 = 0;
            this.axWebBrowser1.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);

mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;
            //MessageBox.Show(doc2.documentElement.innerHTML);

            StringBuilder sb2 = new StringBuilder();

            sb2.Append(doc4.documentElement.innerHTML);
            str2 = string.Empty;
            str2 = sb2.ToString();

The answer to your problem is in my previous code. You're loading a
new page in the control, and then immediately try to retrieve it. You
should wait until the control loads the new page, since it's an
asynchronous operation. A quick Google search for "MSHTML ReadyState
DoEvents" will tell you all you need to know.
 
One thing that is worth remembering at all times when working with
MSHTML in general is that all load operations are asynchronous. In
other words, when you ask it to load a page, you should not expect to
see that page in the control (or obtainable via its properties) in the
next line of code. If you're using the WinForms WebBrowser control,
you should handle DocumentCompleted event. If you're using MSHTML
directly, you have to look at its documentation to determine what is
the analog there - I do not recall it, but I believe it had something
to do with readyState property, which is set to "complete" upon
completion.

here is the code that is keeping the previous webpage instead of the
new one that is being called (in other words, it isn't changing to the
new website that is in the string array below):

object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];  <--the new
website is in here, but isn't being brought up by the following code
(contains last website).
            object null_obj_str2 = "";
            System.Object null_obj2 = 0;
            this.axWebBrowser1.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);

mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;
            //MessageBox.Show(doc2.documentElement.innerHTML);

            StringBuilder sb2 = new StringBuilder();

            sb2.Append(doc4.documentElement.innerHTML);
            str2 = string.Empty;
            str2 = sb2.ToString();

The answer to your problem is in my previous code. You're loading a
new page in the control, and then immediately try to retrieve it. You
should wait until the control loads the new page, since it's an
asynchronous operation. A quick Google search for "MSHTML ReadyState
DoEvents" will tell you all you need to know.
 
here is the code that is keeping the previous webpage instead of the
new one that is being called (in other words, it isn't changing to the
new website that is in the string array below):
object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];  <--the new
website is in here, but isn't being brought up by the following code
(contains last website).
            object null_obj_str2 = "";
            System.Object null_obj2 = 0;
            this.axWebBrowser1.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);
mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;
            //MessageBox.Show(doc2.documentElement.innerHTML);
            StringBuilder sb2 = new StringBuilder();
            sb2.Append(doc4.documentElement.innerHTML);
            str2 = string.Empty;
            str2 = sb2.ToString();

The answer to your problem is in my previous code. You're loading a
new page in the control, and then immediately try to retrieve it. You
should wait until the control loads the new page, since it's an
asynchronous operation. A quick Google search for "MSHTML ReadyState
DoEvents" will tell you all you need to know.- Hide quoted text -

- Show quoted text -

I loose focuse after checking the ReadyState and going to this
function:

private void getNextCompanysContactHTML()
{

object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];
object null_obj_str2 = "";
System.Object null_obj2 = 0;
this.axWebBrowser2.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);

if (((int)axWebBrowser1.ReadyState >= 4) & (!axWebBrowser1.Busy))
{
mshtml.HTMLDocumentClass doc4 =
(mshtml.HTMLDocumentClass)this.axWebBrowser2.Document;

What parameters can I pass to this function?

Thanks,
Trint
 
here is the code that is keeping the previous webpage instead of the
new one that is being called (in other words, it isn't changing to the
new website that is in the string array below):
object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];  <--the new
website is in here, but isn't being brought up by the following code
(contains last website).
            object null_obj_str2 = "";
            System.Object null_obj2 = 0;
            this.axWebBrowser1.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);
mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;
            //MessageBox.Show(doc2.documentElement.innerHTML);
            StringBuilder sb2 = new StringBuilder();
            sb2.Append(doc4.documentElement.innerHTML);
            str2 = string.Empty;
            str2 = sb2.ToString();

The answer to your problem is in my previous code. You're loading a
new page in the control, and then immediately try to retrieve it. You
should wait until the control loads the new page, since it's an
asynchronous operation. A quick Google search for "MSHTML ReadyState
DoEvents" will tell you all you need to know.- Hide quoted text -

- Show quoted text -

I loose focuse after checking the ReadyState and going to this
function:

private void getNextCompanysContactHTML()
{

object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];
object null_obj_str2 = "";
System.Object null_obj2 = 0;
this.axWebBrowser2.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);

if (((int)axWebBrowser1.ReadyState >= 4) & (!axWebBrowser1.Busy))
{
mshtml.HTMLDocumentClass doc4 =
(mshtml.HTMLDocumentClass)this.axWebBrowser2.Document;

What parameters can I pass to this function?

Thanks,
Trint
 
One thing that is worth remembering at all times when working with
MSHTML in general is that all load operations are asynchronous. In
other words, when you ask it to load a page, you should not expect to
see that page in the control (or obtainable via its properties) in the
next line of code. If you're using the WinForms WebBrowser control,
you should handle DocumentCompleted event. If you're using MSHTML
directly, you have to look at its documentation to determine what is
the analog there - I do not recall it, but I believe it had something
to do with readyState property, which is set to "complete" upon
completion.
here is the code that is keeping the previous webpage instead of the
new one that is being called (in other words, it isn't changing to the
new website that is in the string array below):
object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];  <--the new
website is in here, but isn't being brought up by the following code
(contains last website).
            object null_obj_str2 = "";
            System.Object null_obj2 = 0;
            this.axWebBrowser1.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);
mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;
            //MessageBox.Show(doc2.documentElement.innerHTML);
            StringBuilder sb2 = new StringBuilder();
            sb2.Append(doc4.documentElement.innerHTML);
            str2 = string.Empty;
            str2 = sb2.ToString();
The answer to your problem is in my previous code. You're loading a
new page in the control, and then immediately try to retrieve it. You
should wait until the control loads the new page, since it's an
asynchronous operation. A quick Google search for "MSHTML ReadyState
DoEvents" will tell you all you need to know.- Hide quoted text -
- Show quoted text -

I loose focuse after checking the ReadyState and going to this
function:

private void getNextCompanysContactHTML()
        {

            object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];
            object null_obj_str2 = "";
            System.Object null_obj2 = 0;
            this.axWebBrowser2.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);

 if (((int)axWebBrowser1.ReadyState >= 4) & (!axWebBrowser1.Busy))
                {
                    mshtml.HTMLDocumentClass doc4 =
(mshtml.HTMLDocumentClass)this.axWebBrowser2.Document;

What parameters can I pass to this function?

Thanks,Trint- Hide quoted text -

- Show quoted text -

I am aware that you are a better programmer than I am...that is why I
ask for your help...
It is probably my lack of understanding, but I can't understand or get
any help from your Vague answers.
sorry,
trint
 
One thing that is worth remembering at all times when working with
MSHTML in general is that all load operations are asynchronous. In
other words, when you ask it to load a page, you should not expect to
see that page in the control (or obtainable via its properties) in the
next line of code. If you're using the WinForms WebBrowser control,
you should handle DocumentCompleted event. If you're using MSHTML
directly, you have to look at its documentation to determine what is
the analog there - I do not recall it, but I believe it had something
to do with readyState property, which is set to "complete" upon
completion.
here is the code that is keeping the previous webpage instead of the
new one that is being called (in other words, it isn't changing to the
new website that is in the string array below):
object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];  <--the new
website is in here, but isn't being brought up by the following code
(contains last website).
            object null_obj_str2 = "";
            System.Object null_obj2 = 0;
            this.axWebBrowser1.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);
mshtml.HTMLDocumentClass doc4 = (mshtml.HTMLDocumentClass)
this.axWebBrowser1.Document;
            //MessageBox.Show(doc2.documentElement.innerHTML);
            StringBuilder sb2 = new StringBuilder();
            sb2.Append(doc4.documentElement.innerHTML);
            str2 = string.Empty;
            str2 = sb2.ToString();
The answer to your problem is in my previous code. You're loading a
new page in the control, and then immediately try to retrieve it. You
should wait until the control loads the new page, since it's an
asynchronous operation. A quick Google search for "MSHTML ReadyState
DoEvents" will tell you all you need to know.- Hide quoted text -
- Show quoted text -

I loose focuse after checking the ReadyState and going to this
function:

private void getNextCompanysContactHTML()
        {

            object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];
            object null_obj_str2 = "";
            System.Object null_obj2 = 0;
            this.axWebBrowser2.Navigate2(ref loc2, ref null_obj2, ref
null_obj2, ref null_obj_str2, ref null_obj_str2);

 if (((int)axWebBrowser1.ReadyState >= 4) & (!axWebBrowser1.Busy))
                {
                    mshtml.HTMLDocumentClass doc4 =
(mshtml.HTMLDocumentClass)this.axWebBrowser2.Document;

What parameters can I pass to this function?

Thanks,Trint- Hide quoted text -

- Show quoted text -

I am aware that you are a better programmer than I am...that is why I
ask for your help...
It is probably my lack of understanding, but I can't understand or get
any help from your Vague answers.
sorry,
trint
 
Back
Top