diff --git a/Effort.Extra/ObjectDataCollection.cs b/Effort.Extra/ObjectDataCollection.cs index ed389b4..0bf33ab 100644 --- a/Effort.Extra/ObjectDataCollection.cs +++ b/Effort.Extra/ObjectDataCollection.cs @@ -9,6 +9,8 @@ namespace Effort.Extra /// internal class ObjectDataCollection : KeyedCollection { + private readonly object locker = new object(); + /// /// Extracts the key from the specified element. /// @@ -28,9 +30,12 @@ protected override Guid GetKeyForItem(ObjectData item) /// The data. public void AddOrUpdate(ObjectData data) { - if (data == null) throw new ArgumentNullException(nameof(data)); - if (Contains(data.Identifier)) Remove(data.Identifier); - Add(data); + lock (locker) + { + if (data == null) throw new ArgumentNullException(nameof(data)); + if (Contains(data.Identifier)) Remove(data.Identifier); + Add(data); + } } /// @@ -41,8 +46,11 @@ public void AddOrUpdate(ObjectData data) /// true, if the key exists, otherwise false. public bool TryGetValue(Guid key, out ObjectData data) { - data = Contains(key) ? this[key] : null; - return data != null; + lock (locker) + { + data = Contains(key) ? this[key] : null; + return data != null; + } } } } \ No newline at end of file