diff --git a/src/Mono.Android/Java.Lang/Thread.cs b/src/Mono.Android/Java.Lang/Thread.cs index 8c6155f41d3..cc45dd16aed 100644 --- a/src/Mono.Android/Java.Lang/Thread.cs +++ b/src/Mono.Android/Java.Lang/Thread.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Android.Runtime; @@ -27,7 +28,7 @@ public RunnableImplementor (Action handler, bool removable) this.removable = removable; if (removable) lock (instances) - instances [handler] = this; + instances.AddOrUpdate (handler, this); } public void Run () @@ -41,7 +42,7 @@ public void Run () Dispose (); } - static Dictionary instances = new Dictionary (); + static ConditionalWeakTable instances = new (); public static RunnableImplementor Remove (Action handler) {