Skip to content

Commit

Permalink
[Fix] Properly stop polling
Browse files Browse the repository at this point in the history
  • Loading branch information
AleXr64 committed Oct 11, 2023
1 parent c19240e commit b6239d2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion TGBotFramework/BotFramework/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Bot: IHostedService, ITelegramBot
private TelegramBotClient client;
private EventHandlerFactory factory;

private readonly CancellationTokenSource _stopPollingSource = new();
private readonly LinkedList<Type> _wares;

private string _userName;
Expand All @@ -55,6 +56,7 @@ async Task IHostedService.StopAsync(CancellationToken cancellationToken)
{
await client.DeleteWebhookAsync(cancellationToken:cancellationToken);
await client.CloseAsync(cancellationToken);
_stopPollingSource.Cancel();
}

private async Task StartListen(CancellationToken cancellationToken)
Expand Down Expand Up @@ -109,7 +111,7 @@ private async Task StartListen(CancellationToken cancellationToken)
}
else
{
client.StartReceiving(new DefaultUpdateHandler(HandleUpdateAsync, HandleErrorAsync), cancellationToken);
client.StartReceiving(new DefaultUpdateHandler(HandleUpdateAsync, HandleErrorAsync), _stopPollingSource.Token);

}
}
Expand Down

0 comments on commit b6239d2

Please sign in to comment.