Printing Component Message while executing loop

Hi,

I have several methods that run a bit longer.
It is basically for loop, that runs for some time.

I would like to write component message that says how many loops are made at each loop iteration.

The issue with grasshopper component, is that it executes the all for loop iterations and only then displays message - once after all the code is executed.

To display message at each iteration do I need to prepare component similar to timers? with expire solution?

To display a message on screen you’ll have to yield processing cycles to the UI message pump. This will then process any keyboard and mouse events that have been queued, as well as repaint messages that cause the screen to update. As you can imagine, each time you allow the messages to be processed you’ll have to wait a while, thus slowing down your loop even further. Is that still something you wish to pursue?

You won’t need a new solution, but if you repaint the canvas with half the components in an unsolved state they’ll probably all appear orange.

An alternative is to put your entire process into a non-UI thread, let it run with progress callbacks, and update the UI whenever you please. Then, once your process is complete, do you store your results into some sort of local variable and trigger a new solution in which you assign your computed data to the outputs.

But during this time any components which depend on your component will also appear orange, unless you really start to meddle with the expiration logic.

Hi David,

Thanks for a reply.

I do not care if connected components will have error until something is being processed also if it is more slow.

Is it possible to get sample how to a create loop in other thread? The loop only smoothes mesh from existing rhino common methods.

Dear David,

Maybe it is possible to get example running for loop in another thread? =)

threadingExample.gh (5.8 KB)

This file shows how to start and abort threads for long running processes, how to even have a modicum of progress report (although there are cheaper ways than timers) and how to do something when the process finishes.

If you’re doing this in Visual Studio, I’d highly recommend you use the TPL (task-parallel-library, System.Threading.Tasks) instead of messing about with threads directly.

1 Like

Thank you