diff --git a/PorygonSharp/EvalValues/ObjectEvalValueHandler.cs b/PorygonSharp/EvalValues/ObjectEvalValueHandler.cs index 1e5f359..2ea8682 100644 --- a/PorygonSharp/EvalValues/ObjectEvalValueHandler.cs +++ b/PorygonSharp/EvalValues/ObjectEvalValueHandler.cs @@ -1,5 +1,5 @@ using System; -using System.Collections.Generic; +using System.Collections.Concurrent; using System.Runtime.InteropServices; namespace PorygonSharp.EvalValues @@ -18,7 +18,7 @@ namespace PorygonSharp.EvalValues } } - private static readonly Dictionary CreatedPointers = new Dictionary(); + private static readonly ConcurrentDictionary CreatedPointers = new ConcurrentDictionary(); public static IntPtr GetObjectPtr(object o) { @@ -31,13 +31,13 @@ namespace PorygonSharp.EvalValues } else { - CreatedPointers.Remove(hash); + CreatedPointers.TryRemove(hash, out _); } } var handle = GCHandle.Alloc(o, GCHandleType.WeakTrackResurrection); var ptr = GCHandle.ToIntPtr(handle); ptrObject = new PtrObject(ptr, new WeakReference(o)); - CreatedPointers.Add(o.GetHashCode(), ptrObject); + CreatedPointers.TryAdd(o.GetHashCode(), ptrObject); return ptrObject.Pointer; } }