Create another Modern Window in a new STA Thread

Apr 24, 2015 at 4:02 AM
I already have a main window(Modern window), I want to create another window in a new STA thread.But I get the error
"cannot access freezable Shell.WindowChrome across threads bec it cannot be frozenause"

For traditional window It is OK.

My Code as follow:
private void ModernWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var demoThread = new Thread(new ThreadStart(
                delegate()
                {
                    ModernWindow w = new ModernWindow();
                    w.Closed += (sender1, e1) => w.Dispatcher.InvokeShutdown();
                    w.Show();
                    System.Windows.Threading.Dispatcher.Run();
                }
                ));
            demoThread.SetApartmentState(ApartmentState.STA);
            demoThread.IsBackground = true;
            demoThread.Start();
        }
Thank you very much
Apr 24, 2015 at 5:52 AM
I find a solution my-self.

code:
private void ModernWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var demoThread = new Thread(run);
            demoThread.Start();
        }

        private void run(object obj)
        {
            App.Current.Dispatcher.Invoke(new Action(
                    () =>
                    {
                        var dlg = new ModernWindow();
                        dlg.ShowDialog();
                    }
                ));
        }