Asynchronously adding floating params to Grasshopper canvas

Hi there! We’re writing a Rhino plugin that interacts with Grasshopper via named pipes. Each piece of communication that comes in through that pipe triggers an event that is handled by a Grasshopper component. We’ve been able to successfully add and rename groups, change param properties and so on.

However, when we try adding a new param to the canvas we get some really strange UI behavior. We’ve been expiring solution and components using GH.Instances.ActiveCanvas.BeginInvoke(new Action(() => { } ); which worked well for all of the aforementioned cases. However, when we try to add a param expiring the solution, the preview or invalidationg canvas does not really help.

@DavidRutten We do realize that Grasshopper was not designed to be thread safe and that this is not the intended use of the SDK - we’re not at all surprised to be running into issues haha. But given what we’re trying to do (add a GH param when a message comes in through the pipe) - what would be the best way to approach it? Thanks in advance!

1 Like

This is saying that whatever you put inside the Action delegate is running on the UI Thread. This is just how you invoke threadsafe calls on any Wpf, Eto or Forms app. The Canvas is a UserControl (or a wrapper of it) and holds a Dispatcher instance. But whatever you invoke from here relating the UI Thread is obviously threadsafe. Still I don’t really understand at which point you are encountering problems. Can you share some code?

1 Like

Hi @TomTom - as it happens half the time, it turned out to be a very stupid issue that all of us totally missed. We’ve been using doc.Objects.Add() instead of doc.AddObject(). And the funny thing is that we’ve been burnt on this before haha. Everything works great now. Thanks!