Search code examples
c#.netfacebook-likewebbrowser-controlbackgroundworker

Unable to use WebBrowser Control inside a form that is Loaded from background Worker?


I have a windows form application with Two forms, Login and Account

In the Login form, i have backgroundWorker1

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{

// doing some heavy work ...

Account acc = new Account(entered_username, entered_password, true);
acc.ShowDialog();
acc.Dispose();
}

//....

And Button1

//...

private void Button1_Click(object sender, System.EventArgs e)
    {

        showOrHideLoading();
        backgroundWorker1.RunWorkerAsync();

    }

//...

When i click on button1, the Account form appears correctly but after adding a WebBrowser Control to the Account form, the application doesn't work as expected, and when i click on Button1, nothing happens!

Is there any limitation of using WebBrowser Control with BackgroundWorker ?

I need to display a link (to facebook like button) using WebBrowser, is there an alternative way to display html content inside Windows Forms Application without using WebBrowser control.


Solution

  • Unless you have a good reason, try to always keep UI on the same thread.

    Put your "heavy work" in the background thread and display a progress dialog or whatever.

    Once that completes, THEN launch the web browser form.