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 0346f4e commit 6a84e6d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion TGBotFramework/BotFramework/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class Bot: IHostedService, IBotInstance

private EventHandlerFactory factory;

private CancellationTokenSource _recieveToken = new CancellationTokenSource();

public Bot(IServiceProvider services, IServiceScopeFactory scopeFactory, Type startupType = null)
{
this.services = services;
Expand All @@ -50,6 +52,7 @@ async Task IHostedService.StopAsync(CancellationToken cancellationToken)
{
await client.DeleteWebhookAsync(cancellationToken: cancellationToken);
await client.CloseAsync(cancellationToken);
_recieveToken.Cancel();
}

public string UserName { get; private set; }
Expand Down Expand Up @@ -120,7 +123,7 @@ private async Task StartListen(CancellationToken cancellationToken)
await client.DeleteWebhookAsync(false, cancellationToken);

var receiverOptions = new ReceiverOptions { AllowedUpdates = { }, ThrowPendingUpdates = false };
client.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, cancellationToken);
client.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, _recieveToken.Token);
}
}

Expand Down

0 comments on commit 6a84e6d

Please sign in to comment.