C# 如何使用sendtextmessageasync方法?

C# 如何使用sendtextmessageasync方法?,c#,telegram,telegram-bot,C#,Telegram,Telegram Bot,我想使用sendtextmessageasync方法,但我不能用适当的值填充第一个和最后一个重载 private static void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e) { Telegram.Bot.Types.KeyboardButton button1 = new Telegram.Bot.Types.KeyboardButton("a"); Teleg

我想使用
sendtextmessageasync
方法,但我不能用适当的值填充第一个和最后一个重载

private static void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
   {
        Telegram.Bot.Types.KeyboardButton button1 = new Telegram.Bot.Types.KeyboardButton("a");
        Telegram.Bot.Types.KeyboardButton button2 = new Telegram.Bot.Types.KeyboardButton("b");
        Telegram.Bot.Types.KeyboardButton button3 = new Telegram.Bot.Types.KeyboardButton("c");
        Telegram.Bot.Types.KeyboardButton button4 = new Telegram.Bot.Types.KeyboardButton("d");

        Telegram.Bot.Types.KeyboardButton[] row1 = { button1, button2 };
        Telegram.Bot.Types.KeyboardButton[] row2 = { button3, button4 };

        Telegram.Bot.Types.KeyboardButton[][] keyboard = { row1, row2 };

        Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup markup = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup(keyboard);

        bot.SendTextMessageAsync(e.Message.Chat.Id, "Hi", , false, false, 0, markup, );

        Console.WriteLine("A new message has been recieved");
   }
我认为这应该给你一个正确的开始

var reply = "<b>Hello</b>\n"
            + "<a href=\"https://www.google.de\">This is a link</a>\n"
            + "<code>and a little bit code</code>";

await Bot.SendTextMessageAsync(message.Chat.Id, reply, parseMode: ParseMode.Html);

如果当前方法和所有调用方法都具有async关键字,则可以使用wait命令等待结果,并返回
Task
Task
,其中T是要返回的类型<代码>变量结果=等待SendTextMessageAsync()

否则,您可以使用
SendTextMessageAsync.ConfigureAwait(false).GetAwaiter().GetResult()
,但这并不理想,因为它可能导致死锁,除非调用路径中的所有调用都使用
ConfigureAwait(false)
。此命令表示结果可以在任何线程上返回

更多信息可在此处找到: