Try to only stop the bot once

This was causing errors on CTRL+C.
This commit is contained in:
Basique Evangelist 2020-05-16 23:46:59 +03:00
parent 09c07e6296
commit 3544f521f9
Signed by untrusted user: BasiqueEvangelist
GPG Key ID: B370219149301706

View File

@ -27,6 +27,7 @@ namespace JetKarmaBot
RequestChain Chain; RequestChain Chain;
Task timeoutWaitTask; Task timeoutWaitTask;
CancellationTokenSource timeoutWaitTaskToken; CancellationTokenSource timeoutWaitTaskToken;
private bool stopped = false;
public async Task Init() public async Task Init()
{ {
@ -52,6 +53,7 @@ namespace JetKarmaBot
public async Task Stop() public async Task Stop()
{ {
if (stopped) return;
Client.StopReceiving(); Client.StopReceiving();
timeoutWaitTaskToken.Cancel(); timeoutWaitTaskToken.Cancel();
try try
@ -61,6 +63,7 @@ namespace JetKarmaBot
catch (OperationCanceledException) { } catch (OperationCanceledException) { }
await Timeout.Save(); await Timeout.Save();
Dispose(); Dispose();
stopped = true;
} }
#region service #region service