diff --git a/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs b/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs index 1689e74af..98e547f80 100644 --- a/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs +++ b/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs @@ -34,6 +34,8 @@ namespace BTCPayServer.HostedServices public async Task StopAsync(CancellationToken cancellationToken) { + if (_Stop == null) + return Task.CompletedTask; _Stop.Cancel(); try { diff --git a/BTCPayServer/HostedServices/BaseAsyncService.cs b/BTCPayServer/HostedServices/BaseAsyncService.cs index 4b8c85512..1bc6ca2ec 100644 --- a/BTCPayServer/HostedServices/BaseAsyncService.cs +++ b/BTCPayServer/HostedServices/BaseAsyncService.cs @@ -59,6 +59,8 @@ namespace BTCPayServer.HostedServices public Task StopAsync(CancellationToken cancellationToken) { + if (_Cts == null) + return Task.CompletedTask; _Cts.Cancel(); return Task.WhenAll(_Tasks); } diff --git a/BTCPayServer/HostedServices/InvoiceWatcher.cs b/BTCPayServer/HostedServices/InvoiceWatcher.cs index 4e62f3d24..ec413dc2d 100644 --- a/BTCPayServer/HostedServices/InvoiceWatcher.cs +++ b/BTCPayServer/HostedServices/InvoiceWatcher.cs @@ -333,6 +333,8 @@ namespace BTCPayServer.HostedServices public Task StopAsync(CancellationToken cancellationToken) { + if (_Cts == null) + return Task.CompletedTask; leases.Dispose(); _Cts.Cancel(); var waitingPendingInvoices = _WaitingInvoices ?? Task.CompletedTask;