Use Rhino.UI.Dialogs from worker threads

What is the best way to open Rhino.UI.Dialogs from another thread and get the result?
Do i have to use RhinoApp.InvokeOnUiThread ?
How can this return the Dialog result instead of void

Does RhinoCommon expose it’s UI therad as SynchronisationContext?

Then it would fit nicely into an F# Async workflow.

( I am working on a library, not a plugin, the library might already be loaded from a non UI thread)

Hi @Goswin,

Just curious, what are you trying to do and why from another thread?

– Dale

Hi @dale I am using my F# scripting editor (@nathanletwory knows it).
It evaluates F# scripts on another thread. This is nice because it keeps the editor window alive while running my scripts.
However for UI dialogs I need to switch back to the UI thread. So it would be convenient to have the Synchronisation Context of the UI thread exposed on RhinoCommon.

I am aware that it is probably not always safe to manipulate the RhinoDoc from another thread. But so far I had no problems doing it. I would be curious what you think of this.

Hi @Goswin,

I don’t have a quick answer for this. I’ve make a YouTrack item to look into it.

https://mcneel.myjetbrains.com/youtrack/issue/RH-55175

– Dale

I found a workaround. The running F# scripts have to reference the running editor plugin rhp file.
In the editor plugin I created a property called SynchronizationContext. It gets set to System.Threading.SynchronizationContext.Current when the plugin is loaded.

It would be nicer if this property was on RhinoCommon which is always referenced.
I think Rhino.RhinoApp could also have a property called SynchronizationContext
It would be set to System.Threading.SynchronizationContext.Current when RhinoCommon is first loaded.