我想在 WPF 项目中实现命令行运行。App.cs 中的入口点已更改。但是控制台只会闪烁然后消失。如何解决?谢谢
public class App : System.Windows.Application
{
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0)
{// Commandline run mode
// Command line given, console from console
Console.WriteLine("In cmd line mode");
AllocConsole();
CmdLineRun.ParseArgs(args);
CmdLineRun.CmdRun();
}
else
{// GUI mode
GUIMain();
}
}
static void GUIMain()
{
App app = new App();
app.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
app.Run();
}
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private static extern bool AllocConsole();
}