Skip to content

Commit 6bc1000

Browse files
authored
Properly stop polling (#178)
[FIX] Properly stop polling
1 parent cbf4589 commit 6bc1000

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

TGBotFramework/BotFramework/Bot.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public class Bot: IHostedService, IBotInstance
3232
private TelegramBotClient client;
3333

3434
private EventHandlerFactory factory;
35-
35+
36+
private CancellationTokenSource _recieveToken = new CancellationTokenSource();
37+
38+
3639
public Bot(IServiceProvider services, IServiceScopeFactory scopeFactory, Type startupType = null)
3740
{
3841
this.services = services;
@@ -50,6 +53,7 @@ async Task IHostedService.StopAsync(CancellationToken cancellationToken)
5053
{
5154
await client.DeleteWebhookAsync(cancellationToken: cancellationToken);
5255
await client.CloseAsync(cancellationToken);
56+
_recieveToken.Cancel();
5357
}
5458

5559
public string UserName { get; private set; }
@@ -125,7 +129,7 @@ private async Task StartListen(CancellationToken cancellationToken)
125129
await client.DeleteWebhookAsync(false, cancellationToken);
126130

127131
var receiverOptions = new ReceiverOptions { AllowedUpdates = { }, ThrowPendingUpdates = false };
128-
client.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, cancellationToken);
132+
client.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, _recieveToken.Token);
129133
}
130134
}
131135

TGBotFramework/BotFramework/BotFramework.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<ItemGroup>
3232
<PackageReference Include="HttpToSocks5Proxy" Version="1.4.0" />
3333
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
34-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.1" />
34+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.2" />
3535
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
3636
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.119">
3737
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)