I have 2 windows in my project.
One is a "loading" window that I am hoping to display on startup, while the other window loads.
The other is the main window, that runs several queries, and therefore takes a little while to load.
Currently, I have a thread that shows the startup window, then loads the main window with a second thread.
However, once the main window has finally loaded, I want the startup window to be hidden, but I'm not sure how to do that, as it is part of another thread.
Putting both windows in the same thread causes the startup window to lag a lot, due to the main window loading in the same thread.
Any suggestions?
private void Application_Startup(object sender, StartupEventArgs e)
{
Thread MainWindow_Show = new Thread(new ThreadStart(() =>
{
MainWindow MainWindowObj = new MainWindow();
MainWindowObj.Show();
System.Windows.Threading.Dispatcher.Run();
}));
MainWindow_Show.SetApartmentState(ApartmentState.STA);
MainWindow_Show.IsBackground = true;
Thread StartupWindow_Show = new Thread(new ThreadStart(() =>
{
Startup StartupWindow = new Startup();
StartupWindow.Show();
MainWindow_Show.Start();
System.Windows.Threading.Dispatcher.Run();
}));
StartupWindow_Show.SetApartmentState(ApartmentState.STA);
StartupWindow_Show.IsBackground = true;
StartupWindow_Show.Start();
}