Hello,
we are developing a plugin with WPF UI. Some functions are executed on a seperated thread and since our upgrade to Rhino 8 we experiencing a bug, where the UI freezes during adding and removing layers.
This is how our plugin should behave. In Rhino 7 everything works fine:
With Rhino 8 the Layer View Panel freezes when we start our commands:
I uploaded a the sample projects from the pictures above, which mimics some basic functionalities of our plugin: wegewitzSte/RhinoLayerError_demonstration (github.com)
Here you see the code, which causes the error:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
// Start a background task
Task.Run(() =>
{
doc.Views.RedrawEnabled = false;
for ( int i = 0; i < 10; i++ )
{
var layername = $"Building::{i}_{System.Guid.NewGuid()}";
// own version of adding a layer by path parten::child::etc...
int layerIndex = stuff.addLayerByFullPath(doc, layername.ToString(), System.Drawing.Color.DarkBlue);
}
doc.Views.RedrawEnabled = true;
doc.Views.Redraw();
});
return Result.Success;
}
Using a backgroundtask in Rhino 7 seems to work fine, but in Rhino 8 not.
I found a quick fix by using the RhinoUI Thread by using RhinoApp.InvokeOnUiThread , which seems to fix it in Rhino 8:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
// Start a background task
Task.Run(() =>
{
RhinoApp.InvokeOnUiThread((System.Action) (() =>
{
doc.Views.RedrawEnabled = false;
for ( int i = 0; i < 10; i++ )
{
var layername = $"Building::{i}_{System.Guid.NewGuid()}";
// own version of adding a layer by path parten::child::etc...
int layerIndex = stuff.addLayerByFullPath(doc, layername.ToString(), System.Drawing.Color.DarkBlue);
}
doc.Views.RedrawEnabled = true;
doc.Views.Redraw();
}));
});
return Result.Success;
}
Currently this fix is working for us, since we could isolate the function which are changing things with the layers. But iām questioning if this is working as intended.
Is there maybe a better fix or could this be fixed with newer Rhino 8 versions?
Thank You!