Getting result of worker

Playing around with workers. Is there a good way to abstract the result of a worker? The example hard-couples the worker result and the window. I need to get files in a folder to a class. I don’t have a better idea that using a global.

Store your results in a property I’d guess. I’d previously never looked at workers, and now I really wish I didn’t. I would suggest building your own helper, this system sucks.

1 Like

Workers seems to be super simple. I also can’t find a way to cancel a worker.

Too simple. There’s no instantiating, there’s no running multiple, everything is global.

It reads like you can cancel your worker with MyWorker.Stop Worker — Xojo documentation

2 Likes

.Stop ?

You may want to send json with the folder path or file paths to read (JobRequested event) then in the worker load the folderitems. The result will be in jobCompleted event or if you halfway want to parse info you could use SendProgress (progressData As String) from the JobRun event (the worker actually) and use the JobProgressed (progressData As String) event to handle this.

I have that working. It’s the easy part. I select a folder and the worker get’s the subfolders.

How it the .stop supposed to be initiated from the main app?

From a Cancel button or perhaps a Timer as a timeout.

1 Like

How would the cancel be communicated to the worker? The worker is started with .Start and then the worker either finishes or it gives back an error.

Call the Stop method from the main app (while the worker runs, of course) and the worker will halt.

Thanks. It was the usual case of autocomplete not working.