2

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

1 回答 1

0
    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()。

于 2016-08-16T14:38:25.347 回答