Progressbar implementation in main window (Grasshopper component developer)



Hi all.

I have a component which opens a window for fitness landscape visualisation. I’d like to implement a progressbar when this visualisation refreshes (via a button clicked in the main window). Because the refreshing takes a while to run, the refreshing code typically runs as a BackgroundWorker class, while the progressBar takes on the UI thread.

However the refreshing involves retrieving information from another component which requires expiring the solution, and calls to Grasshopper UI should only be called in the main UI thread.

Running the progress bar in the backgroundWorker class does not work. (Is it because the thread is pushed to a lower priority than the main thread?) The progress bar does not show (until the refresh is complete, so it flickers into existence for a moment and then immediately exits).

Is there a way I can implement the progress bar in my main window? I would like for the user to know that the code is not hanging when it’s doing the task of refreshing.

(David Rutten) #2

Whenever you wish to call UI code (or code which ultimately calls UI code on the same thread) you must invoke that method on the UI thread. In RhinoCommon you can use the RhinoWindow.Invoke method to pass a delegate which will then be invoked from the UI thread.

Within Grasshopper Redraw and Solution scheduling can be done from any thread, since it involves a timer which will correctly trigger the code when it ticks.


Does that mean that if I want two pieces of UI code to run simultaneously, and one of them takes a lot of time, it’s impossible to show both running?