C# Mono Console.ReadLine quitting

本文关键字:quitting ReadLine Console Mono | 更新日期: 2023-09-27 18:10:07

我正在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();

C# Mono Console.ReadLine quitting

    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;
        }
    }
}}

我想这与单声道无关,你可以试试Console.ReadKey()吗