Display some text in a window before long running process starts

A button on a window starts to retrieve lots of records from a database. I would like to display some text after button has been clicked and before retrieving records.
At the moment the text is not displayed after retrieve ends.

What are my options to overcome that problem ?

OS X, M1, 2020r2

You start by showing us your code. You probably need to use a thread. And before starting the thread you update the text.

Hi Johann, see if this can help you.
You can insert in the window a Label without text (Label1.Text="") then in the pressed event of the button first show some text in the label (Label1.Text=“Please Wait …”) then start retrieving records.
At the end remove the text from the label (Label1.Text="").
On my pc it works.


Domenico, it does not work for me, the text displayed after all records retrieved.

Beatrix, how would a thread work in this case ?
have never used a thread before!

When you do a long task the interface is blocked. Updating the interface in a long task is always a PITA. Check out the threads example in the Xojo folder. For instance, there is a folder “UpdatingUIFromThread” with 2 example files.

Add a Thread and a Timer to the Window and in the Run Event of this Thread, you put your Code to retrieve the Data.
Let this Thread load the Data into an Object you can reach outside of the Thread, like in a RowSet as a Property of the same Window. Set the Priority of the Thread to 2,3 or 4.

Then in your Button, you change the Label and afterwards, start the Thread. But always chek if the Thread is in a NotRunning State, before you try to start it. :wink:

The Thread can Start the Timer as soon as the Thread has finished the Job. The Timer can do whatever needs to be done with the Data the Thread retrieved.

I usually do it with the timer function. In the button’s Pressed event you put this code:

Label1.Text = “Loading…”
Timer.CallLater(1, WeakAddressOf retrieveData)

retrieveData is a separate method on the same window.

With this however, you cannot change the label’s text as soon as you have started retrieving the data. So no progress percentages for example.

I’d always vote for Threads (or Workers) when it comes to pull data from an external source or if the dataload is really heavy. Because connection issues, long calcs, etc. can make your app freeze.


I have never done that before, but I’m giving it a try, just out of curiosity how it works,

thanks to all

1 Like

thanks Christopher,
works perfect, and it is for sure the easiest way to implement.