I am trying to create some UserControl(s) using another thread, and I am using code like this:
private void btnDemo_Click(object sender, RoutedEventArgs e)
{
Task tsk = Task.Factory.StartNew(() =>
{
for (int i = 0; i < 3; i++)
{
MyControl sprite = new MyControl();
pnlTest.Children.Add(sprite);
}
});
}
But I am getting this exception in the UserControl constructor:
The calling thread must be STA, because many UI components require this.
I am not sure that I am using the right approach to do this. Please, Can you help me with this.
thanks.