compute.rhino3d
compute.rhino3d copied to clipboard
C# compute client should provide awaitable methods
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.
async void DoStuff(IEnumerable<Brep> breps)
{
var union = await BrepCompute.CreateBooleanUnion(breps);
// do more stuff
}
// or
var task = BrepCompute.CreateBooleanUnion(breps);
while (!task.Wait(250))
{
// keep ui alive
// check timeout
}
var res = task.Result;
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;
or BrepComputeAsync.CreateBooleanUnion()
or BrepCompute.CreateBooleanUnionAsync()
.
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;
}