As the 'reachableVertices' list is declare as field the usage of this list inside IsConnected is not Thread safe.
The list is only used inside the function and cleared before every usage, I suggest to use an local list instead.
This will make the function Thread safe and will also reduce memory usage.
private bool IsConnected(MyInventory dstInventory) { var srcConveyor = (this.Owner as IMyConveyorEndpointBlock); if (srcConveyor != null) { var reachableVertices = new List<IMyConveyorEndpoint>(); MyGridConveyorSystem.FindReachable(srcConveyor.ConveyorEndpoint, reachableVertices, (vertex) => vertex.CubeBlock != null); foreach (var vertex in reachableVertices) { if (dstInventory.Owner == vertex.CubeBlock) { return true; } } } return false; }
As the 'reachableVertices' list is declare as field the usage of this list inside IsConnected is not Thread safe. The list is only used inside the function and cleared before every usage, I suggest to use an local list instead. This will make the function Thread safe and will also reduce memory usage.
private bool IsConnected(MyInventory dstInventory) { var srcConveyor = (this.Owner as IMyConveyorEndpointBlock); if (srcConveyor != null) { var reachableVertices = new List<IMyConveyorEndpoint>(); MyGridConveyorSystem.FindReachable(srcConveyor.ConveyorEndpoint, reachableVertices, (vertex) => vertex.CubeBlock != null); foreach (var vertex in reachableVertices) { if (dstInventory.Owner == vertex.CubeBlock) { return true; } } } return false; }