Open pearswj opened 4 years ago
Linked with COMPUTE-115
A solution for running compute API calls without freezing rhino (this example calls EvaluateDefinition for grasshopper, but could work with any other call) :
// make api call
List<GrasshopperDataTree> output;
try
{
var asyncoutput = Task.Run(()=>EvaluateDefinition(grasshopperFile, trees));
while (! asyncoutput.IsCompleted) // while Task is not yet completed
{
Rhino.RhinoApp.Wait(); // Rhino keeps running while waiting
}
output = asyncoutput.Result; // gets result
}
catch (AggregateException ae) // exceptions happen inside Task
{
ae.Handle((x) =>
{
if (x is System.Net.WebException)
{
// handle error
return true;
}
return false;
});
return;
}
Some functionality could take a while to solve and it would be nice if the C# client included awaitable methods to simplify backgrounding out of the box.
We might need another namespace or an additional set of classes/methods, so as not to mess with anyone currently using the synchronous methods, e.g.
using Rhino.ComputeAsync;
orBrepComputeAsync.CreateBooleanUnion()
orBrepCompute.CreateBooleanUnionAsync()
.