【发布时间】:2012-03-29 18:30:36
【问题描述】:
我正在编写一个同时具有 CLI 和 GUI 的应用程序。
我阅读了大多数关于它的问题和文章,发现这个问题非常有用:
Can one executable be both a console and GUI application?
我的最终代码如下:
if (args.Length > 0)
{
//console code
}
else
{
FreeConsole();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form());
}
这在通过双击运行 .exe、调试或从带有参数的控制台运行时非常有用。
但是,在不带参数的情况下从控制台运行它时,GUI 会按照我的预期打开,但控制台会卡住等待 GUI 关闭。
这是非典型的 GUI 和控制台行为。控制台通常会启动 GUI,而不是等待其退出,而是等待新命令。
有办法避免吗?
【问题讨论】:
标签: c# user-interface console-application command-line-interface