Hello,
i have a problem with threading in WPF. I want to have created a complex user interface and then i want to add it to my main-window. While this complex user interface is creating i want to show a progress bar in my main window. I think this only could be made with threads. But there is a problem. The created element can't be added to main window because it is created in a separate thread. Do anybody know if there is a possibility to transfer UIElements that are created in a background-thread to the main-thread. If i try in a simple way it says that the object can't be accessed because it is in a separate thread. I have already made my progress-bar thread safe.
I hope following example explain a bit better what i want to to.
StackPanel tcForm = new StackPanel();
Semaphore loadedSema = new Semaphore(0,1);
Thread thread = new Thread(new ThreadStart(delegate(){
//Formular should be created in background
tcForm.Children.Add(new Formular());
ProgressBar.AddProgress();
//...other things
loadedSema.Release();
}));
thread.start();
loadedSema.WaitOne();
new Formular()
runs a very long time, so i thought about creating in background.
It is also impossible to add Formular
to a variable and then add it main thread.
//this is also impossible
//in background-thread
form = new Formular
//in main-thread
tcForm.Children.Add(form);
I hope that there is a way to this. Would be nice if there are some advices,
Thanks, Martin