I am using Parallel loops to speedup my code since I have to perform this on a large data set but I keep getting null errors while intersecting the geometry or trimming the curves while the original code without parallel loops works fine. the one with parallel loops runs sometimes but gives errors on another time. Can anybody suggest what should the solution

```
Parallel.ForEach(g, (Geometry geom) =>
{
bool intersection = s.DoesIntersect(geom);
if (intersection)
{
ConcurrentQueue<Geometry[]> s_geom = new ConcurrentQueue<Geometry[]>();
s_geom.Enqueue(geom.Intersect(s));
foreach (Geometry SgeomInt in s_geom.ToList()[0])
{
if (DSCore.Object.Type(SgeomInt) == "Autodesk.DesignScript.Geometry.Line")
{
Curve curve = SgeomInt as Curve;
Curve trimCurve = curve.TrimByParameter(0.001, 0.999);
double curveLength = trimCurve.Length;
curvelengths.Enqueue(curveLength);
trimmedCurves.Enqueue(trimCurve);
}
}
}
});
```