|
@@ -35,18 +35,28 @@ namespace WCS.Core
|
|
|
|
|
|
private static ConcurrentDictionary<World, ConcurrentDictionary<object, object>> ExObjsOfWorld = new ConcurrentDictionary<World, ConcurrentDictionary<object, object>>();
|
|
|
|
|
|
- private static T GetExOfWorld<T>(this object source, World world)
|
|
|
+ static T GetExOfWorld<T>(this object source, World world)
|
|
|
{
|
|
|
if (!ExObjsOfWorld.TryGetValue(world, out var objs))
|
|
|
{
|
|
|
- objs = new ConcurrentDictionary<object, object>();
|
|
|
- ExObjsOfWorld[world] = objs;
|
|
|
+ ExObjsOfWorld.TryAdd(world, new ConcurrentDictionary<object, object>());
|
|
|
+ objs = ExObjsOfWorld[world];
|
|
|
}
|
|
|
|
|
|
- if (objs.TryGetValue(source, out var obj)) return (T)obj;
|
|
|
- obj = Activator.CreateInstance(typeof(T), source, world);
|
|
|
- objs[source] = obj;
|
|
|
+ if (!objs.TryGetValue(source, out var obj))
|
|
|
+ {
|
|
|
+ lock (objs)
|
|
|
+ {
|
|
|
+ if (!objs.ContainsKey(source))
|
|
|
+ {
|
|
|
+ obj = Activator.CreateInstance(typeof(T), source, world);
|
|
|
+ objs.TryAdd(source, obj);
|
|
|
+ }
|
|
|
+ obj = objs[source];
|
|
|
+ }
|
|
|
+ }
|
|
|
return (T)obj;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public static DataBlock Ex(this DBInfo source, World world)
|