控制檯項目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();
}
}
即可實現從控制檯中啓動想要的窗體