C#テストアプリケーションでwpfウィンドウを開こうとしました。しかし、ウィンドウを開くと、すぐに再び閉じられます。
私のコードの何が問題になっていますか?
Main.cs(ここでも入手可能):
namespace Project1
{
class TestClass
{
public static MainWindow _mainWindow = null;
static void Main(string[] args)
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.SetApartmentState(ApartmentState.STA);
t.Start();
while (true)
{
System.Threading.Thread.Sleep(1000);
_mainWindow.ToString();
}
}
public static void ThreadProc()
{
TestClass2 testClass = new TestClass2();
testClass.Open();
}
}
class TestClass2
{
public void Open()
{
TestClass._mainWindow = new MainWindow();
TestClass._mainWindow.Show();
Console.WriteLine("=)");
}
}
}
MainWindow.xaml: