You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is code sample of IUpdateHandler implementation:
public class TelegramHandler : IUpdateHandler
{
public async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
{
try
{
//disable internet connection at this point
if (update.Type == UpdateType.Message)
await botClient.SendTextMessageAsync(update.Message.Chat.Id, "test");
}
catch { }
}
public Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
{
//this will be called in endless loop, while internet is off
Console.WriteLine("error");
return Task.CompletedTask;
}
}
Now, do the following:
Put breakpoint at line if (update.Type == UpdateType.Message)
Send message to the bot to hit breakpoint
Disable your internet connection
Release breakpoint
Watch at console output and CPU load 😊
This happens because of call _botClient.MakeRequestAsync inside loop:
Which is going to exception handler:
Probably some workaround can be done by catching HttpRequestException and invoking Task.Delay(1000)
The text was updated successfully, but these errors were encountered:
depler
changed the title
Endless loop in error handler
Endless loop in error IUpdateHandler, HandleErrorAsync
Dec 4, 2021
depler
changed the title
Endless loop in error IUpdateHandler, HandleErrorAsync
Endless loop in IUpdateHandler, HandleErrorAsync
Dec 4, 2021
Here is code sample of IUpdateHandler implementation:
Now, do the following:
if (update.Type == UpdateType.Message)
This happens because of call
_botClient.MakeRequestAsync
inside loop:Which is going to exception handler:
Probably some workaround can be done by catching
HttpRequestException
and invokingTask.Delay(1000)
The text was updated successfully, but these errors were encountered: