From 433daede0e55718e6c77055f1070d2c652511789 Mon Sep 17 00:00:00 2001 From: sakno Date: Wed, 4 Dec 2024 22:29:09 +0200 Subject: [PATCH] Fixed ObjectDisposedException --- .../Threading/LinkedCancellationTokenSourceTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/DotNext.Tests/Threading/LinkedCancellationTokenSourceTests.cs b/src/DotNext.Tests/Threading/LinkedCancellationTokenSourceTests.cs index a252b3665..60bf3cf3b 100644 --- a/src/DotNext.Tests/Threading/LinkedCancellationTokenSourceTests.cs +++ b/src/DotNext.Tests/Threading/LinkedCancellationTokenSourceTests.cs @@ -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); } } \ No newline at end of file