I have the following code for creating tabpages to a predefined list:
private void CreateControls()
{
Parallel.ForEach(_websites,
w =>
{
var tabPage = new TabPage(w.Name);
var webBrowser = new WebBrowser();
webBrowser.Navigate(w.Url);
tabPage.Controls.Add(webBrowser);
WebPagesTabControl.TabPages.Add(tabPage);
});
}
I am getting the following exception:
cannot be instantiated because the current thread is not in a single-threaded apartment.
What is the correct way to set the apartment state to STA?