控制台项目Project1,程序代码,如:
class Program
{
private static Thread _thread;
static void Main(string[] args)
{
_thread = new Thread(TestClass.Show);
_thread.SetApartmentState(ApartmentState.STA);//设置为 STA 才能操作UI
_thread.Start();
Console.ReadLine();
}
}
界面项目Project2,程序代码,如:
public static class TestClass
{
private static Window1 _window1;
public static void Show()
{
_window1 = new Window1();
_window1.ShowDialog();
}
}
即可实现从控制台中启动想要的窗体