Skip to content

Commit

Permalink
Fixed ObjectDisposedException
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Dec 4, 2024
1 parent ea22d63 commit 433daed
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public static async Task ConcurrentCancellation()

using var cts = token.LinkTo([source1.Token, source2.Token]);
NotNull(cts);
ThreadPool.UnsafeQueueUserWorkItem(Cancel, source1, preferLocal: false);
ThreadPool.UnsafeQueueUserWorkItem(Cancel, source2, preferLocal: false);
ThreadPool.UnsafeQueueUserWorkItem(Cancel, source3, preferLocal: false);
var task1 = source1.CancelAsync();
var task2 = source2.CancelAsync();
var task3 = source3.CancelAsync();

await token.WaitAsync();

Contains(cts.CancellationOrigin, new[] { source1.Token, source2.Token, source3.Token });

static void Cancel(CancellationTokenSource cts) => cts.Cancel();
await Task.WhenAll(task1, task2, task3);
}
}

0 comments on commit 433daed

Please sign in to comment.