Multithreading with rhinocommon

In multithreading, is it safe to use RhinoApp.MainApplicationWindow.Invoke(new Action(delegate { MyMethodWorkingWithRhinoDoc(parameters); })); to perform actions on rhino doc?

It should be a good way to do it.


Giulio Piacentino
for Robert McNeel & Associates

By my test looks like it works too… But… another question… i’m having some bug report from costumers about rhino crashing while tring to open a 3dm file on idle event of rhino and doing some work on rhino geometries right after RhinoDoc.ReadFile() function.
The call stack that i get is always going to say:
Exception has been thrown by the target of an invocation. —> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Making me wonder that some c++ ptr has been changed while i’m performing a loop in rhino objects right after loading the file… the code on idle event is like this:

public void RhinoAppIdle(object sender, EventArgs e)
            RhinoApp.Idle -= RhinoAppIdle;

            RhinoDoc.ReadFile(fullPathFileToLoad, fileReadOptions);
            Transform translation = Transform.Translation(offsetX, offsetY, offsetZ);
            int layerIndexDefault = RhinoDoc.ActiveDoc.Layers.FindByFullPath("DEFAULT_LAYER", true);
            var rhinoObjects = RhinoDoc.ActiveDoc.Objects.FindByLayer(RhinoDoc.ActiveDoc.Layers[layerIndexDefault]);
            List<GeometryBase> listGeometryBases = new List<GeometryBase>();

            if (rhinoObjects == null || rhinoObjects.Length <= 0)

            foreach (var rhinoObject in rhinoObjects)
                GeometryBase geometryBase = rhinoObject.Geometry;
                if (geometryBase == null)

                GeometryBase duplicatedGeometryBase = geometryBase.Duplicate();
                if (translation != Transform.Identity)
            //then add geometries to RhinoDoc from listGeometryBases

The main problem is that i cant repeat the error in my computer… just to test it i’ve notice that if i put only the read file function in the Invoke of the rhino main window i have to put a RhinoApp.Wait(); to see the objects loaded using FindByLayer… but if i put inside the Invoke call all the code in the idle event i dont need to call to Wait()… so more questions comes in my head… do i have to put a RhinoApp.Wait() always to let rhino end his jobs? Is there anything that need to be done after reading a file?

@Matteoz991I started a new thread. Please start new threads when you have new questions.