Popup while multithreading (rhinocommon): "This action cannot be completed because the other program is busy."

I’d see how Parallel.ForEach fares. It’s for sure the easiest if you are OK with hiding the threading entirely.

It isn’t going to make a difference it the main thread is locked up waiting for all of the other threads to complete. We use the ‘get with timeout’ approach in things like Make2d

I’m not having much luck with multithreading, so I’m thinking I could take another approach, which might actually be better for what I’m trying to do:
have an external program that launches instances of rhino and automatically calls a command to start a simulation, then when finished exits rhino.

How might I do this? Are there any .net projects already set up to do something like this?

Thanks,
Sam

External access is done through a process called automation.

https://wiki.mcneel.com/developer/automation

Thanks Steve, I’ve got that working (code I copied below), though some issues/questions.

  • I see Rhino come up under background processes in task manager, but it doesn’t disappear after exit is called. How can I make sure Rhino closes?
  • Sometimes the geometry isn’t created. I think this is happening when I don’t end task on the rhino in background processes before opening a new instance. I’m hoping I can run multiple rhino instances, so any thoughts on how to get around this?
  • Is there a way you recommend to send information back to the automation program? I’m thinking I might just generate a text file and then continuously check it…

Thanks,
Sam

' Create Application or Interface object On Error Resume Next Dim objRhino = CreateObject("Rhino5x64.Interface") 'Dim objRhino = CreateObject("Rhino5.Application") If (Err.Number <> 0) Then MsgBox("Failed to create Rhino5 object") Exit Sub End If
    ' Make attempts to get RhinoScript.
    ' Sleep between each attempt.
    Dim nCount As Integer
    nCount = 0
    Dim objRhinoScript As Object
    Do While (nCount < 10)
        On Error Resume Next
        objRhinoScript = objRhino.GetScriptObject()
        If Err.Number <> 0 Then
            Err.Clear()
            Sleep(500)
            nCount = nCount + 1
            MsgBox(nCount)
        Else
            Exit Do
        End If
    Loop

    If (objRhinoScript Is Nothing) Then
        MsgBox("Failed to get RhinoScript")
    End If

    Call objRhino.RunScript("_Circle 0 10", 0)
    Call objRhino.RunScript("_Line -5,-5,0 5,5,0", 0)
    Call objRhino.RunScript("_Line 5,-5,0 -5,5,0", 0)
    Call objRhinoScript.Echo("Geometry created.")
    Call objRhino.RunScript("_-Save C:\Users\Sam.lochner\Desktop\test.3dm _enter ", 0)
    Call objRhinoScript.Echo("File saved.")
    Call objRhino.RunScript("_Exit ", 0)
    Call objRhinoScript.Echo("Done!")