Hello everyone,
I’m developing a C# application that needs to run Rhinoceros 8 in headless mode to perform background processing tasks. Multiple instances of this application can run at the same time, each one launching a different Rhino instance.
To launch Rhino, I’m using code based on the Automation Sample in the following way:
private dynamic rhino;
try {
const string rhino_id = "Rhino.Application.8";
var type = Type.GetTypeFromProgID(rhino_id);
rhino = Activator.CreateInstance(type);
} catch (Exception e){
// exception handling
}
if (null == rhino) {
// error handling
}
while (0 == rhino.IsInitialized()) {
Thread.Sleep(100);
time_waiting += 100;
if (time_waiting > bail_milliseconds) {
// error handling
}
}
The Issue:
In some cases—especially when Rhino doesn’t have an active license or cannot open properly—my application hangs indefinitely during the CreateInstance call. The exception catch block is not triggered, so the application stays in the Activator.CreateInstance(type); line without handling the error.
Problem Details:
The behavior I’m seeing is unpredictable and inconsistent:
• Sometimes each instance of my process creates and launches Rhino one at a time. After about a minute, the Rhino instances close, and the exception is caught.
• Other times it takes 20 minutes, or it hangs indefinitely.
• Occasionally, multiple Rhino instances launch simultaneously, or Rhino continues running even after the calling process has been terminated.
This unpredictability is problematic because:
-
I don’t receive a handle to the Rhino process from Activator.CreateInstance, so I can’t close specific instances directly.
-
Rhino doesn’t terminate when my application closes, leading to accumulated instances over time, which could affect system performance.
Question:
How can I reliably detect and manage Rhino instances created by my application? Specifically:
• Is there a way to ensure Rhino closes when the calling process is terminated?
• How can I prevent multiple lingering Rhino instances if there’s an issue launching it?
Thank you in advance for any advice!