Update User Interface in a thread

Earlier, I had the code in the thread in this way:

1. Collect data from settings. 2. Run the loop, Update status during the process. 3. Update status when finish.

But then, the UI is not possible to update in a thread and I made the code like this:

–> Button: collect data from settings.
–> Thread: Loop data. Insert status in a local variable.
–> Timer: Show the local variable as the status.
–> ??? Update User Interface, the status.

How do I update the User Interface when the loop is done!?
(I still think this feature sucks major. It adds a lot of trouble but offers no opportunities, as far as I can tell…)

It seems your solution is already there. You have your thread “insert statue in a variable” when it finishes. Have your timer periodically check the value of that variable and, if it is such that it indicates the thread has finished, proceed to your step 4.
You do understand that “not updating the GUI from a thread” is not a “feature” arbitrarily inserted into the language by Xojo, Inc. to make our lives tougher. It is the modern OSs that require that the GUI be only updated by the main thread.

Thank you! I was not aware of that.
So, it’s an OS issue rather than Xojo… It’s strange, because the OS has been around for quite some time and it used to work pretty good. Oh, well!! Time changes! Then, it’s more acceptable…

Still, sort of pointless.

The problem is the last step.
Yes, you are right. The previous steps are solved!
Well… I just add some more thinking and the problem will be either solved or removed!

This isn’t a new issue. Xojo (and formerly REALsoftware) has advised their customers for many years that updating the user interface from any but the main thread was a bad thing and would lead to problems sooner or later. What’s new is that following this advice is now enforced (because it had to be).

This is due to changes in the AppKit framework of Mac OS X some time ago (AppKit - the UI framework - is not thread-safe).

All right.
I just have to deal with it! Thank you for clearing this out!
REALBasic / Xojo is just such a neat, fast developing tool… For me, this feature just adds to the confusion.
But at the other hand, if it will assure my code to work like magic on a Mac, then it’s defiantly worth the efforts!!

Here is how I solved it, and I think it’s working also IRL on a Mac…! :slight_smile:

[code]PushButton code:

IF me.caption = “Scan” THEN
me.caption = “Stop”

intStartPage = CDbl(txtSettingsStartPage.text)
intStopPage = (CDbl(txtSettingsStopPage.text)-1) * 10

' ## SCAN
bolScan = TRUE

timerScan.Mode = Timer.ModeMultiple

// Let's get to work...

me.caption = “Scan”

// Let's get to work...

' ## SCAN
bolScan = TRUE

timerScan.Mode = 0

' ## BATCH


Timer code: IF bolScan = TRUE THEN txtResult.text = strSERPResult textStatus.text = strStatus ELSE IF btnScan.caption = "Stop" THEN loadBatch btnScan.caption = "Scan" textStatus.text = "Ready" timerScan.Mode = 0 END IF END IF