Skip to content

Commit c889767

Browse files
committed
Fix InvalidOp when enumerating the SystemClockChanged hashset
1 parent 04d98ea commit c889767

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Rx.NET/Source/src/System.Reactive/Internal/SystemClock.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ private static void OnSystemClockChanged(object sender, SystemClockChangedEventA
5959
{
6060
lock (SystemClockChanged)
6161
{
62-
foreach (var entry in SystemClockChanged)
62+
// create a defensive copy as the callbacks may change the hashset
63+
var copySystemClockChanged = new List<WeakReference<LocalScheduler>>(SystemClockChanged);
64+
foreach (var entry in copySystemClockChanged)
6365
{
6466
if (entry.TryGetTarget(out var scheduler))
6567
{

0 commit comments

Comments
 (0)