Hi guys,
I am basically doing something similar as mentioned in this post, however my question is not 100% related to the discussion, so I figured I better create a new topic.
So I am writing a custom component opening a new form, which calls an optimization running in the background, similar to galapagos or goat. The optimization method manipulates the sliders and retrieves the result from the grasshopper file. It should be possible to cancel or force stop the optimization, so I though a background worker which runs the optimization on a separate thread and monitors for cancel requests on the main form might make sense. The problem is, that the optimization itself manipulates the sliders and thus the UI thread from the background worker thread. So the following happens:
- If I just call the methods (e.g. set slider values or ExpireSolution) I get an InvalidOperationException in debug mode, also it doesn’t really seem safe to me, as one can manipulate the gh doc while the optimization is running and probably crash it.
- If I invoke the functions with BeginInvoke the UI thread including the cancel button freezes again.
Any ideas how to deal with that properly? I noticed Galapagos also freezes / blurs out the gh document, so it cannot be manipulated while the galapagos form is open and running.
Thanks,
Daniel