How to invoke a SolutionExpired on the GH_DocumentEditor

Hello all!

Does anyone now how I can Invoke a GH Solution recompute from another thread?

I tried to call a Me.ExpireSolution(True) on a dedicated component which can communicate with a WCF Process but I faced a lot of issue, like InterThread Operation Exception (sounds quite aggressive)

Then I found this old post from David :

So, I guess that’s exactly what I am experiencing. Question is, what should I write after
Dim editor As GH_DocumentEditor = Grasshopper.Instances.DocumentEditor
editor.Invoke( ??? )
to trigger a recompute of the GH solution?

Thanks for your help!

In order to invoke a method on the UI thread, you can use the Invoke method on any user interface object (form, control, whatever). I think you can also use the Invoke method on RhinoWindow.

For simulate Recompute button:
Dim canvas As Grasshopper.GUI.Canvas.GH_Canvas = Grasshopper.Instances.ActiveCanvas
If canvas.IsDocument Then canvas.Document.NewSolution(True)

This will not solve the problem, since you should not call the NewSolution method from a non-UI thread. If you’re on a different thread, the call to NewSolution must be invoked via a UI object.

Ok, thanks to both of you, what I did and looks to be working is

Delegate Sub MySubDelegate(bool As Boolean)

Public Sub ExpireComponent() 'Called from a Non-UI Thread
Dim comp as GH_Component _
[Get a component here]
Dim editor As GH_DocumentEditor = Grasshopper.Instances.DocumentEditor

Dim msd As MySubDelegate = AddressOf comp.ExpireSolution_
editor.Invoke(msd, {True})
End sub

So far, no more exceptions have been raised.