File tree 1 file changed +15
-2
lines changed
src/Adapter/MSTest.TestAdapter/Execution
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
+ using System . Collections . Concurrent ;
5
+
4
6
namespace Microsoft . VisualStudio . TestPlatform . MSTest . TestAdapter ;
5
7
6
8
/// <summary>
@@ -10,8 +12,9 @@ public class TestRunCancellationToken
10
12
{
11
13
/// <summary>
12
14
/// Callbacks to be invoked when canceled.
15
+ /// Needs to be a concurrent collection, see https://github.com/microsoft/testfx/issues/3953.
13
16
/// </summary>
14
- private readonly List < Action > _registeredCallbacks = new ( ) ;
17
+ private readonly ConcurrentBag < Action > _registeredCallbacks = new ( ) ;
15
18
16
19
/// <summary>
17
20
/// Stores whether the test run is canceled or not.
@@ -63,7 +66,17 @@ private set
63
66
/// <summary>
64
67
/// Unregister the callback method.
65
68
/// </summary>
66
- public void Unregister ( ) => _registeredCallbacks . Clear ( ) ;
69
+ public void Unregister ( )
70
+ #if NETCOREAPP || WINDOWS_UWP
71
+ => _registeredCallbacks . Clear ( ) ;
72
+ #else
73
+ {
74
+ while ( ! _registeredCallbacks . IsEmpty )
75
+ {
76
+ _ = _registeredCallbacks . TryTake ( out _ ) ;
77
+ }
78
+ }
79
+ #endif
67
80
68
81
internal void ThrowIfCancellationRequested ( )
69
82
{
You can’t perform that action at this time.
0 commit comments