Together with what you quoted, I have something like this in my code, but it’s been a while since I wrote this, so I don’t recall all the details. In the form where all this is running there is a field:
private AutoResetEvent waitHandle;
and at some point during construction I subscribe to the event.
mainDocument.SolutionEnd += new GH_Document.SolutionEndEventHandler(OnSolutionEnd);
waitHandle = new AutoresetEvent(false);
The definition of the EvendHandler:
private void OnSolutionEnd(object sender, GH_SolutionEventArgs e)
And the AutoResetEvent needs to be Reset before the optimization starts. So you schedule the solution, then waitHandle.WaitOne() which freezes this thread until the solution is over, which triggers the SolutionEnd event which sets the AutoResetEvent so that the other thread can continue running (and collect results from the component).