Question

I work with the MAF in WPF and I have problems with the UI threads. I would like that each AddIn that I activate become a unique UI thread.

Why do I want that you probably wondering? I try to explain :-)

I have a host application which is a container for addins. Different people developing addins for the host. If a developer start a long procedure in their addin and they forget to Invoke or start the procedure in a thread, the host will freeze because the host and the addins share the same UI thread.

Every addin run in a seperatly appdomain. About every hint I would be happy.

Was it helpful?

Solution

you could try the following approach:

Thread thread = new Thread(() =>
{
 Window1 w = new Window1();
 w.Show();

 //make sure to stop the Dispatcher when window is closed
 w.Closed += (s, e) => w.Dispatcher.InvokeShutdown();
 //start the message pump
 System.Windows.Threading.Dispatcher.Run();
});

thread.SetApartmentState(ApartmentState.STA);
thread.Start();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top