I have an event subscription from PRISM in Background Thread. After Login I load several Application related Data. Also I try to resolve the MainMenu from Unity Container.
MainMenu mainMenu = container.Resolve<MainMenu>();
This will end with an exception. It must be called from an STA Thread because the operations are GUI related. This seems totally understandable, but
So how do I load GUI related stuff inside a background Thread?
Try creating a thread with the STA
ApartmentState:
Thread uiThread = new Thread(() =>
{
mainMenu = container.Resolve<MainMenu>();
// Allow the main UI thread to proceed
System.Windows.Threading.Dispatcher.Run();
});
uiThread.SetApartmentState(ApartmentState.STA);
uiThread.IsBackground = true;
uiThread.Start();