Hey,
I created a component, that needs to do some heavy computations. If the computation is done in the solve instance function the whole UI freeze and waits for it. That’s why I make the computation in an extra thread. That works fine for me, but the problem is after the computation finished and the new result is set to the output, the next component does not start a recomputation. Is there any command to start a new computation for the following components or do I need to all totally different. Below you can see my code.
Best Regards
public class SampleComponent : GH_Component
{
public SampleComponent()
: base("SampleComponent", "Nickname", "Description", "Category", "Subcategory")
{ }
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddIntegerParameter("Number", "Number", "Number", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddIntegerParameter("Result", "Result", "Result", GH_ParamAccess.item);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
int number = 0;
if (!DA.GetData(0, ref number)) { return; }
int res = 1;
Task computingTask = new Task(() =>
{
for (int i = 0; i < number; i++)
{
res = res + res;
}
Params.Output[0].ClearData();
DA.SetData(0, res);
//Ping/Start new computation of the next component
});
computingTask.Start();
DA.SetData(0, null);
}
protected override System.Drawing.Bitmap Icon
{ get { return null; } }
public override Guid ComponentGuid
{
get { return new Guid("9a4e60bb-c6fc-47d7-acbe-698723e162a0"); }
}
}