UI becomes unresponsive while using Web browser control even though it is been used and invoked from a separate thread
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4269800/webbrowser-control-in-a-new-thread">WebBrowser Control in a new thread</a>  </p>
</blockquote>



<p>I'm developing a Winforms application which has the following controls in it. A textbox, WebBrowser control, and 3 Richtextboxes. </p>

<p>Purpose of this app is that when I enter a URL in the textbox, web browser should navigate me to that page, and then I would be parsing the HTML source of webpage to pickup all the hyperlinks, and again I would be filtering those hyperlinks into valid and invalid hyperlinks. </p>

<p>As of now I'm declaring web browser control in a different thread, and when the navigated event of the web browser fires, then I would be creating one more thread which would do all the parsing stuff which I have mentioned above. The problem is that the application is becoming unresponsive when the web browser is loading the webpage, even though I'm invoking it from a separate thread. </p>

<p>Do we have a workaround for this? </p>

<p>Here is the code through which I'm creating a separate thread for web browser control.</p>

<pre><code>Thread t2 = null;

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
        if (e.KeyChar == (char)13)
        {
            if((textBox1.Text.StartsWith("www") || textBox1.Text.StartsWith("WWW")))
            {
               textBox1.Text = textBox1.Text.Insert(0,"http://");

            }
            if (!(textBox1.Text.EndsWith(".html") || textBox1.Text.EndsWith(".htm")))
            {
                textBox1.Text = textBox1.Text + "/";
            }
            t2 = new Thread(new ParameterizedThreadStart(ActivateBrowser));
            t2.IsBackground = true;
            t2.SetApartmentState(ApartmentState.STA);
            t2.Start(textBox1.Text);
        }
    }

    public void ActivateBrowser(Object URL)
    {
        String url = (string)URL;
        WebBrowserNavigation(url);            
    }

    public delegate void PassURLDelegate(string URL);

    public void WebBrowserNavigation(string URL)
    {
        if (webBrowser1.InvokeRequired)
        {
            this.BeginInvoke(new PassURLDelegate(WebBrowserNavigation), new object[] { URL });
        }
        else
        {
            webBrowser1.Navigate(URL);
        }
    }
</code></pre>
