feklee
January 22, 2020, 7:48am
1
I created a counter component. It asynchronously expires itself every half a second:
private void expireSolutionAfterDelay(IGH_DataAccess DA)
{
Task.Delay(500).ContinueWith((task) => {
ExpireSolution(true);
});
}
protected override void SolveInstance(IGH_DataAccess DA)
{
DA.SetData(0, counter);
expireSolutionAfterDelay(DA);
counter++;
}
Project.zip (879.4 KB)
When I insert this component I get:
What am I doing wrong?
I hope this example is not over simplified and helps me solve the actual more complex problem: Data is received asynchronously from a server. The component should expire itself every time a new data package is received.
nathanletwory
(Nathan 'jesterKing' Letwory)
January 22, 2020, 8:49am
2
I think you need to invoke ExpireSolution(true)
on the UI thread.
feklee
January 22, 2020, 12:14pm
3
I’m lost: How do I do that?
At the moment, I call ExpireSolution(true)
on the component, which according to documentation I think should be the right thing to do.
If you like, you can open my project . It’s stripped down to the bare minimum to replicate the issue.
feklee
January 22, 2020, 1:06pm
5
Thanks, it works with RhinoApp.InvokeOnUiThread()
!
I changed:
Task.Delay(500).ContinueWith((task) => {
ExpireSolution(true);
});
To:
var d = new ExpireSolutionDelegate(ExpireSolution);
Task.Delay(500).ContinueWith((task) => {
Rhino.RhinoApp.InvokeOnUiThread(d, true);
});
With:
public delegate void ExpireSolutionDelegate(Boolean recompute);
1 Like