I am getting this error when I am passing browser control to my background tasks which keep track of browser control values. What change do I need in code so I can pass this browser control safely to my background scraper class.
Error
The calling thread must be STA, because many UI components require this.
Here is how I am passing browser control to my background singleton class.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
brwser.Navigate("https://xyz.com");
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Task.Factory.StartNew(() =>
{
if (BfScrapper.Instance.CanStart)
BfScrapper.Instance.StartTask(brwser);
});
}
}