Event Definitions accessible inside a thread ?

Dear Friends out there,
I apologize, this may be a stupid question actually, but I’m somehow stuck here… maybe someone can help me…

This is the situation:
There is a class that does some complex calulations and database actions and runs for some seconds which (if I would put it directly into a window as control) would block the GUI in updating while the class executes when I put it into a window. The class uses some event definitions to propagate status information to the surrounding world.

Now, the thought was to wrap the class into a thread to decouple it from the gui and have the class run in the thread. Good - but all the event definitions aren’t accessible any more… can someone give me a hint on how to get the event definitions of this class being a property in the tread (right now) being accessible again or raise the event definitions “one level up” so that the class can communicate with the GUI again ?

For me it’s not necessary that the class is a property in the thread, it just should run somehow in the thread… if there is a better method, I’d be happy for any suggestion !

Thank you sincerely,

There is a Task class that comes with Xojo that may help you. Look in the Examples folder for “UIThreadingWithTask.xojo_binary_project”.

Or you can do this by starting a Timer within the Thread that will raise the event. Timers always run on the main thread no matter how they are started.

Hi Kem T,
thank you for the speedy reply. I’m not sure if this might help, but I’ll give it a try for sure.
Look, the thing that makes me stuck right now is is that there is a class doing calculations on a single image file which raises event definitions of the class depending on progress steps.
I can put the class as a property inside the thread (maybe that’s the wrong approach), but I cannot pick the events raised by the class for further processing or putting things one level up into the GUI, I haven’t seen a way yet to position an event handler inside the thread that reacts on the event definitions raised by the class inside the thread…

Use AddHandler to wire the events to methods. Note, however, that the events run in the thread that raised them, which in your case will be the sub thread, not the GUI thread, so they will not be able to update the UI directly. So it’s AddHandler to tie the event to a method that fires up a Task or Timer.