As expected, this will wait a few milliseconds, then write to Rhino’s console to notify that the task has completed.
However, modifying it to Waiter(100).Wait()) (which would normally just cause the Task to execute synchronously) never appears to return, hence Grasshopper/Rhino hangs. It doesn’t throw any exceptions and attaching a debugger to Rhino doesn’t yield any insight.
It seems that the thread executes, but never yields, hence the UI stall.
Now, I’m not sure if I’ve got my .net versioning mixed up (understanding that Rhino/GH is net45) or the details of how the ScriptInstance compiler works but I expected this to work out of the box given that the intellisense is picking up the async and await keyboards to begin with (C# 5+).
What’s also interesting is that it still prints and displays in the Rhino command line, suggesting that it completes properly and Rhino is running, but GH is still holding control / doing something. Another tell would be that the UI doesn’t show as normal windows ‘not responding’, but the windows UI elements flicker:
CPU profiling shows that the Wait() call is still running:
But I can’t figure out how that works - because Rhino still prints the message to console, which would suggest that Wait() has returned, the GH solution is finished and Rhino’s UI thread is not blocked…
Hi Ivan, sorry for a basic question. Where can I find the GH component on your Github page? I’m having a problem using a Python component which loads for 10s each time. And finding a solution to make the Rhino/GH not freezing while the component is loading. Thanks in advance!
Hi @Cheung_Henrik
The goal of this was slightly different to not freezing the definition (in fact, it was supposed to - the goal was to allow using async syntax in script components.
What you’ll need to do is slightly different - I don’t use ghpython much so someone else can chime in here with the syntax, but essentially:
When your component starts updating, store a local state i.e. “isUpdating” and let the solution end. Output some placeholder data or a temporary state
When your long asynchronous task finishes, schedule a new solution and expire your component during the solution. When your component updates this time, set “isUpdating” to false and output the results.
Thank Cameron for the explanation. Although I at last resolved by Solution Async plugin, your explanation helped me to understand the logic behind (I suppose the principle is similar)!
And also it appears to me that C# seems to have more potential, if we want to work with lower levels programming in Rhino/Grasshopper.