aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/CommonExtensions.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-11-14 17:33:29 -0600
committerGitHub <noreply@github.com>2026-11-14 17:33:29 -0600
commit1f4754f40005af6e1110bd00c7a7705a7203287a (patch)
tree75a0a97c55d513ae5fb3cca281f6acc406c0bdd4 /src/slskd/Common/CommonExtensions.cs
parent2622c9b698fa27ebfcc7239b75334cac96b7e88a (diff)
parent3cf8cc9eafe3214431ea914772be7766d0db324a (diff)
downloadslskd-1f4754f40005af6e1110bd00c7a7705a7203287a.tar.gz
Merge pull request #1921 from slskd/object-disposed
Fix a bug causing an error when a download fails to enqueue after 180 seconds
Diffstat (limited to 'src/slskd/Common/CommonExtensions.cs')
-rw-r--r--src/slskd/Common/CommonExtensions.cs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs
index 47e4aee1..5affdf5c 100644
--- a/src/slskd/Common/CommonExtensions.cs
+++ b/src/slskd/Common/CommonExtensions.cs
@@ -231,6 +231,25 @@ namespace slskd
}
/// <summary>
+ /// Safely cancels this <see cref="CancellationTokenSource"/> without throwing if it is disposed.
+ /// </summary>
+ /// <param name="cts">The CancellationTokenSource instance.</param>
+ /// <param name="swallowObjectDisposedException">A value indicating whether to swallow ObjectDisposedException, if it occurs.</param>
+ /// <returns>A value indicating whether the cancellation completed successfully.</returns>
+ public static bool Cancel(this CancellationTokenSource cts, bool swallowObjectDisposedException)
+ {
+ try
+ {
+ cts.Cancel();
+ return true;
+ }
+ catch (ObjectDisposedException) when (swallowObjectDisposedException)
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
/// Recursively retrieves all properties.
/// </summary>
/// <param name="type">The type from which to retrieve properties.</param>