WebBrowser.Navigate doesn't load page?

  • Thread starter Thread starter MaartyMan
  • Start date Start date
M

MaartyMan

Hi, I am new to C#. Maybe someone can help me with this: crawlBrowser is a
WebBrowser on my Form. When I use Document.Write below (commented out) the
code gets past the loop, so the page "loads". If I use Navigate, however,
crawlBrowser.IsReady stays in the "Loading" state forever, with
crawlBrowser.IsBusy false, and crawlBrowser.Url doesn't update, stays with
the initialized "about:blank" string. If I remove the loop, however, the page
loads eventually, but I would like to continue with code in this function.
Please help, I've tried everything I can think of and read all the posts I
could find?
//crawlBrowser.Document.Write("test123");
crawlBrowser.Navigate("www.google.com");
while (!IsWebBrowserCompleted())
{
Thread.Sleep(1000);
}

here is the code for method IsWebBrowserCompleted:

private bool IsWebBrowserCompleted()
{
bool ok = false;
switch (crawlBrowser.ReadyState)
{
case WebBrowserReadyState.Interactive:
case WebBrowserReadyState.Complete:
case WebBrowserReadyState.Loaded:
ok = true;
break;

case WebBrowserReadyState.Uninitialized:
case WebBrowserReadyState.Loading:
break;
}

return ok;
}
 
MaartyMan said:
Hi, I am new to C#. Maybe someone can help me with this: crawlBrowser is a
WebBrowser on my Form. When I use Document.Write below (commented out) the
code gets past the loop, so the page "loads". If I use Navigate, however,
crawlBrowser.IsReady stays in the "Loading" state forever, with
crawlBrowser.IsBusy false, and crawlBrowser.Url doesn't update, stays with
the initialized "about:blank" string. If I remove the loop, however, the page
loads eventually, but I would like to continue with code in this function.
Please help, I've tried everything I can think of and read all the posts I
could find?
//crawlBrowser.Document.Write("test123");
crawlBrowser.Navigate("www.google.com");
while (!IsWebBrowserCompleted())
{
Thread.Sleep(1000);
}

here is the code for method IsWebBrowserCompleted:

private bool IsWebBrowserCompleted()
{
bool ok = false;
switch (crawlBrowser.ReadyState)
{
case WebBrowserReadyState.Interactive:
case WebBrowserReadyState.Complete:
case WebBrowserReadyState.Loaded:
ok = true;
break;

case WebBrowserReadyState.Uninitialized:
case WebBrowserReadyState.Loading:
break;
}

return ok;
}

Have you looked at the WebBrowser.DocumentCompleted or WebBrowser.Navigated
events? I think they are better for what you want to do.

Mike
 
Family Tree Mike said:
Have you looked at the WebBrowser.DocumentCompleted or WebBrowser.Navigated
events? I think they are better for what you want to do.

Mike

Thanks for the reply.
I am trying to write a web crawler, to load a page, process it and go to the
next page, etc. I was planning to do this inside a single method. I have
looked at when these events trigger and it seems they only trigger after my
method has finished executing. I'm not sure how I would structure the code
without doing it in the same function?
 
=?Utf-8?B?TWFhcnR5TWFu?= said:
Thanks for the reply.
I am trying to write a web crawler, to load a page, process it and go to the
next page, etc. I was planning to do this inside a single method. I have
looked at when these events trigger and it seems they only trigger after my
method has finished executing. I'm not sure how I would structure the code
without doing it in the same function?

Using a List<> or some other structure, maintain a list of pages to
load. When the complete event fires, process the page, and trigger
loading of the next page in the list.
 
Scott Seligman said:
Using a List<> or some other structure, maintain a list of pages to
load. When the complete event fires, process the page, and trigger
loading of the next page in the list.

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
I'm the one that has to die when it's time for me to die, so let me
live my life, the way I want to.
-- Jimi Hendrix

Thanks, I will try that out. Back to the drawing board :-)
 
Back
Top