2017-02-08 29 views
0

我在電報BOT新寫代碼來BOT檢查消息:
爲什麼我在C#中的電報機器人GetUpdatesAsync中出現錯誤?

var updates = await Bot.GetUpdatesAsync(offset); 
    foreach (var update in updates) 
    { 
     if (update.Message.Text.Contains("hi") || update.Message.Text.Contains("Hi")) 
      { 
      //for first time that code work correct but after 4 hourse in this line 

      var updates = await Bot.GetUpdatesAsync(offset); 
      } 
    } 

得到錯誤,而是因爲在1分鐘後重置Visual Studio中的錯誤解決我無法讀取錯誤,發生什麼事?我該如何解決這個問題?謝謝。

回答

0

如果您使用的桌面應用程序,最好使用調用代碼中的計時器每隔1秒

private void timer1_Tick(object sender, EventArgs e) 
    { 
     yourGetUpdateFunc(); 
    } 

    void yourGetUpdateFunc(){ 
    var updates = await Bot.GetUpdatesAsync(offset); 
    foreach (var update in updates) 
    { 
     if (update.Message.Text.Contains("hi") || update.Message.Text.Contains("Hi")) 
     { 
      // do work 
     } 
     } 
    } 
相關問題