WPF在新线程中打开窗体

时间:2023-02-11 00:54:14

打开窗体

Window win;
Thread t=new Thread(()=>
{
win=new Window();
win.Show();
System.Windows.Threading.Dispatcher.Run();
});
t.IsBackground=true;
t.SetApartmentState(ApartmentState.STA);
t.start();

Thread t2=new Thread(()=>
{
Thread.Sleep(600);
});
t2.IsBackground=true;
t2.start();
t2.Join();

关闭

System.Windows.Threading.Dispatcher.ExitAllFrames();

备忘