Why do I keep getting null errors when using Parallel loops

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);
                            }
                        }
                    }
                });

just to let you know g is a concurrentQueue while s is coming from the list of inputs of the node.
Yes this exercise is for a zeroTouch node. Any help will be appreciated