0

I can load a link into the webBrowser1.Navigate manual by adding a button. But, I can't get it to work while processing from the list box in a loop. Is there a response or wait function that's suppose to be added? Right now all I hear is clicking sounds and nothing happening in the browser control window.

private void start_btn_Click(object sender, EventArgs e)
{
    if (listId.Items.Count != 0 && listCell.Items.Count != 0)
    {
        for (int a = 0; a < listId.Items.Count; a++)
        {
            for (int b = 0; b < listCell.Items.Count; b++)
            {
                MakeReq(txtWebUpdate.Text + listId.Items[a].ToString() + 
                        "&admire=1", listCell.Items[b].ToString());
            }
        }
    }
}

void MakeReq(string Url, string Cell)
{

    try
    {
        txtSetUpdate.Text = (Cell);
        webBrowser1.Navigate(new Uri(Url));
    }
    catch (System.UriFormatException)
    {
        return;
    }

}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
acctman
  • 4,229
  • 30
  • 98
  • 142
  • What exactly are you trying to do? – Evan Mulawski Aug 28 '11 at 20:46
  • @Evan i'm trying to process each link, but as Ash said below it's canceling out each other in the loop process. So I guess I need to add something to make sure the process is complete first? – acctman Aug 28 '11 at 21:23
  • Getting WebBrowser events to fire requires pumping the message loop. I will not mention Application.DoEvents as the workaround, that would be a bad idea. More here: http://stackoverflow.com/questions/5181777/c-application-doevents/5183623#5183623 The proper way is a state machine that's pumped by the DocumentCompleted event. – Hans Passant Aug 29 '11 at 01:02

2 Answers2

2

this is the code i ended up using.

   void WaitBrowserLoading()
    {
        while (webBrowser1.IsBusy)
            Application.DoEvents();
        for (int i = 0; i < 500; i++)
            if (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
                System.Threading.Thread.Sleep(10);
            }
            else
                break;
        Application.DoEvents();
    }
acctman
  • 4,229
  • 30
  • 98
  • 142
1

What is your aim?

Here you just call Navigate which just initiates a navigation. It doesn't care what happens after it starts the process. So in your code the loop initiates several Navigates in a row, each of which cancel the previous on if it has completed yet. Therefore the only one you will actual see complete will be the last one in your list.

Ash Burlaczenko
  • 24,778
  • 15
  • 68
  • 99