Hi guys,
its me again today. I encountered this problem before, but know I decided to post it here to see if anyone can give me any insights. I am converting a List<Point3d>
in to a DataTree<double>
The input can be very large so I want to do it via a parallel forloop
in the code below, everything works fine except when I am trying to add my items to the DataTree, I get an exception message. This makes me think that DataTree
might not be thread safe
?
private void RunScript(List<Point3d> input, ref object A)
{
DataTree<double> dataTree = new DataTree<double>();
int totalBranches = input.Count;
Parallel.For(0, input.Count, i =>
// for (int i = 0; i < input.Count; i++)
{
GH_Path path = new GH_Path(i);
double[] data = new double []{input[i].X,input[i].Y,input[i].Z};
for (int j = 0; j < data.Length; j++)
{
//dataTree.Add(data[j], path); ---> Line which bugs out
}
});
A = dataTree;
}