Explorar o código

Fix InvalidOp when enumerating the SystemClockChanged hashset

akarnokd %!s(int64=6) %!d(string=hai) anos
pai
achega
c4d8342cfc
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      Rx.NET/Source/src/System.Reactive/Internal/SystemClock.cs

+ 3 - 1
Rx.NET/Source/src/System.Reactive/Internal/SystemClock.cs

@@ -59,7 +59,9 @@ namespace System.Reactive.PlatformServices
         {
         {
             lock (SystemClockChanged)
             lock (SystemClockChanged)
             {
             {
-                foreach (var entry in SystemClockChanged)
+                // create a defensive copy as the callbacks may change the hashset
+                var copySystemClockChanged = new List<WeakReference<LocalScheduler>>(SystemClockChanged);
+                foreach (var entry in copySystemClockChanged)
                 {
                 {
                     if (entry.TryGetTarget(out var scheduler))
                     if (entry.TryGetTarget(out var scheduler))
                     {
                     {