gpt4 book ai didi

C# Mono Console.ReadLine 退出

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:10:32 24 4
gpt4 key购买 nike

我正在 linux mint 14 上使用 MONO (C#) 构建应用程序,但我遇到了一些问题。我在选项中启用了外部控制台,在调试时它工作得很好但是在部署之后(在调试文件夹中打开 .exe)应用程序在 Console.ReadLine(); 之后立即退出;有什么想法吗?

public static void InitializeUI() 
{
Console.WriteLine("On the bottom line enter the command \"START\" followed by a space and a number representing on how many hours to check for new posts. You can always stop the execution with Ctrl+C \r\n \r\nExample : START 6");
ParseCMD();
Console.ReadLine ();
}
private static void ParseCMD()
{
string cmd = Console.ReadLine();
string[] commands = cmd.Trim().Split(new string[] {" "},StringSplitOptions.RemoveEmptyEntries);
int delay = 0;
if (commands[0].ToLower() == "start" && int.TryParse(commands[1],out delay))
{
MainLogic.StartLogic(delay);
}
else
{
Console.WriteLine("Wrong command");
ParseCMD();
}
}

之后退出
string cmd = Console.ReadLine();

最佳答案

    public static void Main(string[] args)
{
Console.WriteLine("On the bottom line enter the command \"START\" followed by a space and a number representing on how many hours to check for new posts. You can always stop the execution with Ctrl+C \r\n \r\nExample : START 6");


if(!ParseCMD(readKeey()))
{
ParseCMD(readKeey());
}

}private static string readKeey()
{
ConsoleKeyInfo cki;
Console.TreatControlCAsInput = true;

string temp="";
do
{
cki = Console.ReadKey();
temp=temp+cki.KeyChar;

} while (cki.Key != ConsoleKey.Enter);
return temp;
}

private static bool ParseCMD(string text)
{
try{
string cmd = text;
string[] commands = cmd.Trim().Split(new string[] {" "},StringSplitOptions.RemoveEmptyEntries);
int delay = 0;
if (commands[0].ToLower() == "start" && int.TryParse(commands[1],out delay))
{
Console.WriteLine("Right command you enter:" + commands[0] + commands[1]);
return true;
}
else
{
Console.WriteLine("Wrong command");

return false;
}
}
catch(Exception ex)
{
Console.WriteLine("ex.Message:"+ex.Message);
return false;
}
}
}}

我想这与 Mono 无关,请您尝试使用 Console.ReadKey() 代替。

关于C# Mono Console.ReadLine 退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16128909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com