我试图用下面的代码显示一个winform,但它打开并立即关闭。 我无法理解这个原因。任何想法?为什么不在没有Application.Run()的情况下打开winform?
[STAThread]
static void Main()
{
try
{
AppDomain.CurrentDomain.UnhandledException += AllUnhandledExceptions;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
Test testWin = new Test();
testWin.Show();
}
catch (Exception ex)
{
Logger.Error("Main : " + ex.Message, typeof(Program));
}
}
它的工作正常,如果我用Application.Run(testWin)替换testWind.Show()。
它“打开”很好,只有在程序终止一微秒后才能看到它。 Application.Run()是GUI应用程序中的一个硬性要求,它解决了[生产者 - 消费者问题](http://en.wikipedia.org/wiki/Producer-consumer_problem)。制作人是操作系统,消费者是你的UI。你不消费任何东西。 –