From 0273fb1fdde5f01fc0a545eadb0da23f62ed01ac Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 9 Oct 2025 19:02:39 -0500 Subject: move stateChanged delegate invoke to finally --- src/slskd/Transfers/Downloads/DownloadService.cs | 41 +++++++++++++----------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index db1a92ad..65404945 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -279,29 +279,34 @@ namespace slskd.Transfers.Downloads var topts = new TransferOptions( stateChanged: (args) => { - Log.Debug("Download of {Filename} from user {Username} changed state from {Previous} to {New}", transfer.Filename, transfer.Username, args.PreviousState, args.Transfer.State); - - // prevent Exceptions thrown during shutdown from updating the transfer record with related Exceptions; - // instead, allow these to be left "hanging" so that they are properly cleaned up at the next startup - if (Application.IsShuttingDown) + try { - Log.Debug("Download update of {Filename} to {Username} not persisted; app is shutting down", transfer.Filename, transfer.Username); - return; - } + Log.Debug("Download of {Filename} from user {Username} changed state from {Previous} to {New}", transfer.Filename, transfer.Username, args.PreviousState, args.Transfer.State); - transfer = transfer.WithSoulseekTransfer(args.Transfer); + // prevent Exceptions thrown during shutdown from updating the transfer record with related Exceptions; + // instead, allow these to be left "hanging" so that they are properly cleaned up at the next startup + if (Application.IsShuttingDown) + { + Log.Debug("Download update of {Filename} to {Username} not persisted; app is shutting down", transfer.Filename, transfer.Username); + return; + } - // we don't know when the download is actually enqueued (remotely) until it switches into that state - // when it is enqueued locally is irrelevant, due to internal throttling etc - if (args.Transfer.State.HasFlag(TransferStates.Queued) && args.Transfer.State.HasFlag(TransferStates.Remotely)) - { - transfer.EnqueuedAt ??= DateTime.UtcNow; - } + transfer = transfer.WithSoulseekTransfer(args.Transfer); - // todo: broadcast - SynchronizedUpdate(transfer); + // we don't know when the download is actually enqueued (remotely) until it switches into that state + // when it is enqueued locally is irrelevant, due to internal throttling etc + if (args.Transfer.State.HasFlag(TransferStates.Queued) && args.Transfer.State.HasFlag(TransferStates.Remotely)) + { + transfer.EnqueuedAt ??= DateTime.UtcNow; + } - stateChanged?.Invoke(transfer); + // todo: broadcast + SynchronizedUpdate(transfer); + } + finally + { + stateChanged?.Invoke(transfer); + } }, progressUpdated: (args) => rateLimiter.Invoke(() => { -- cgit v1.2.3