C#在异步void完成后打开一个void

时间:2019-04-13 14:11:05

标签: c#

当我在控制台中按6时,它将打开异步void Mes()。现在,当它完成工作时,我想回到我的静态void Menu()。当我按1时,它应该打开我创建的下一个异步空位,但是当我键入数字并按Enter键后,控制台将关闭。观看下面的代码。

已完成的异步void的代码

public static async void Mes()
        {
            Console.WriteLine("Enter username: ");
            var hg = Console.ReadLine();
            Console.WriteLine("Enter your message: ");
            var mc = Console.ReadLine();
            var uname = await api.GetUserAsync(hg);
            var id = uname.Value.Pk.ToString();
            var ms = await api.SendDirectMessage(id, null, mc);
            Console.WriteLine(ms.Succeeded ? "Successfully sent" : "Couldn't be sent\n\t" + ms.Info.Message);
            Thread.Sleep(1500);
            Menu();
        }

现在将打开静态void Menu(),但在我按下一个数字后,控制台将关闭

public static void Menu()
        {
            Console.WriteLine("Option 1");
            Console.WriteLine("Option 2");
            Console.WriteLine("Option 3");
            Console.WriteLine("Option 4");
            Console.WriteLine("Option 5");
            Console.WriteLine("Option 6");
            string ff = Console.ReadLine();
            if (ff == "1")
            {
                OS();
            }

            if (ff == "2")
            {
                SS();
            }

            if (ff == "3")
            {
                SV();
            }

            if (ff == "4")
            {
                COL();
            }

            if (ff == "5")
            {
                Upl();
            }

            if (ff == "6")
            {
                Mes();
            }
        }

0 个答案:

没有答案