I’ve noticed a very annoying event related bug in c# script component.
After closing and reopening a c# component with event subscriptions all the delegates are subscribed once again. I need to restart Rhino to make all delegates work as expected after each change in my code.
Here is an example:
private void RunScript(bool x, object y, ref object A)
{
GrasshopperDocument.SolutionStart -= PrintStart;
GrasshopperDocument.SolutionStart += PrintStart;
GrasshopperDocument.SolutionEnd -= PrintEnd;
GrasshopperDocument.SolutionEnd += PrintEnd;
}
// <Custom additional code>
public void PrintStart(object sender, GH_SolutionEventArgs e)
{
RhinoApp.WriteLine("Before solution!");
}
public void PrintEnd(object sender, GH_SolutionEventArgs e)
{
RhinoApp.WriteLine("After solution!");
}
You would expect to have
Before solution!
After solution!
in the Rhino command line after each solution is calculated. And it works exactly like that before you reopen c# script, add another empty line or edit your code somehow. Then boom:
Before solution!
Before solution!
After solution!
After solution!
Edit your code once again and get a triple result. And so on.
The only way to reset things to normal is to restart Rhino.
eventBug.gh (2.9 KB)