Hi Paul,
I forgot I was supposed to respond to this, sorry.
ComputeData is part of all active objects in Grasshopper that participate in solutions. ClearData, CollectData, ComputeData is sort of their public api for wiping stale data and generating new data.
The GH_Component base class creates an iterator object inside ComputeData which calls the SolveInstance() method repeatedly, each time with different combinations of input ranges. ComputeData is the bit that makes sure that each required set of input values is handled once. It’s complicated because it has to take into account the optionality of inputs, as well as their access levels (item, list, tree).
If you want to just speed up a calculation using threading, then we have a new mechanism in GH for Rhino6 that helps with that.
However it looks as though you want to calculate stuff in the background for a long time while yielding control back to the UI in the meantime.
I think the following steps are required:
- Override BeforeSolveInstance (which is called only once per solution) and cancel any running tasks. Then move your component into a state where it can begin queuing tasks.
- Inside SolveInstance queue all the tasks you want to start off with, but probably do not start them quite yet. After you’re done queuing, set blank data to the outputs (or, if you’re willing to write extra code, assign the old data again).
- Inside AfterSolveInstance or perhaps in response to the GH_Document.SolutionEnd event, begin running your tasks.
- When all your tasks are complete and they haven’t been interrupted by a new solution (step 1), then trigger a new solution by calling
this.ExpireSolution(true)
*. Your component must be smart enough to distinguish between solutions where it’s supposed to cancel it’s tasks, and those where it’s supposed to harvest the finished data and assign it to outputs.
* do not call that method from a non-UI thread. If you’re not sure whether you’re on a UI thread or not, then you must either Invoke on the UI thread or call GH_Document.ScheduleSolution(), which is threadsafe.