How to create UserControl (any graphical component) in a separate thread and then thread it to the main thread. True the ruler works and it goes back to the main thread. But it seems that it is not possible to produce UserControl in a separate thread from the main thread
public partial class LifePattern : UserControl
{
Thread t;
public LifePattern()
{
InitializeComponent();
t = new Thread(CreateUiElemet);
t.IsBackground = true;
t.SetApartmentState(ApartmentState.STA);
t.Name = "Thread Create Control";
t.Start();
}
private void CreateUiElemet(object obj)
{
// Create in this Thread the Control
UserControl userControl = new UserControl();
// Back to the thread Main
Application.Current.Dispatcher.Invoke(() =>
{
btn_Play.Content = userControl;
//System.InvalidOperationException:
//'The calling thread cannot access this object because a different thread owns it.'
});
}
}