[英]C# Mono Console.ReadLine quitting
我在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()。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.