none
webbrowser control stalls form RRS feed

  • Question

  • Hi guys,

    I've begun experimenting with the webbrowser control and I have placed it in one of my apps, however when the form starts and the webbrowser begins to navigate to the set page it blocks the rest of the form until it completes. Is there any work around for this?

    THanks

    Wednesday, February 6, 2008 2:04 AM

Answers

  • I think the reason you are seeing this problem is that the call to Navigate is not asynchronous and will wait for the page to load before it returns.  You could try making the call to Navigate in a seperate thread, such as:

     

    Code Snippet

    using System.Threading;

     

    private void button1_Click(object sender, EventArgs e)

    {

    ThreadPool.QueueUserWorkItem(new WaitCallback(this.Navigate), "http://www.msdn.com");

    }

     

    private void Navigate(object url)

    {

    if (this.InvokeRequired)

    {

    this.Invoke(new MethodInvoker(delegate()

    {

    this.Navigate(url);

    }));

    }

    else

    {

    this.webBrowser1.Navigate(url.ToString());

    }

    }

     

     

    That should do the trick.
    Wednesday, February 6, 2008 3:08 AM

All replies

  • I think the reason you are seeing this problem is that the call to Navigate is not asynchronous and will wait for the page to load before it returns.  You could try making the call to Navigate in a seperate thread, such as:

     

    Code Snippet

    using System.Threading;

     

    private void button1_Click(object sender, EventArgs e)

    {

    ThreadPool.QueueUserWorkItem(new WaitCallback(this.Navigate), "http://www.msdn.com");

    }

     

    private void Navigate(object url)

    {

    if (this.InvokeRequired)

    {

    this.Invoke(new MethodInvoker(delegate()

    {

    this.Navigate(url);

    }));

    }

    else

    {

    this.webBrowser1.Navigate(url.ToString());

    }

    }

     

     

    That should do the trick.
    Wednesday, February 6, 2008 3:08 AM
  • Thank Veryed,

     

    There is still a slight delay for some reason but its much better than what it was! thanks again!

     

    Wednesday, February 6, 2008 10:41 PM