Order of executions

Hi,

(The following happens inside window.open event:)

On my app I have a method that sorts an array and when the array is large it takes a while and it slows/freezes the app for a few seconds.
Since I want to look professional I thought to add a splash screen that says “…Loading please wait a moment…”
I presume that if I launch the splashscreen before sorting the array then the user should see the message before the wait, since my code is written in this order. But for some reason, It seems like the order of these instructions is ignored and it freezes as usual as if the splaschreen call never existed.
Then it proceeds normally.

Then I tried to use a thread and rearranged like this:

[code]app.showinfo " Please wait. Loading…" ’ this is the splashcreen just a method that displays a label

ThreadSORT.Priority = Thread.HighPriority ’ giving the trhead top maximum power
ThreadSORT.run 'Launches the thread that calls the method that arranges the array

Do
Loop until threadsort.state=4 ’ Splashscreen is supposed to be shown until the thread has finished
[/code]

Again, It won’t show the splashcreen. It seems like it just skips it.

What am I missing here ?
Why things are not executed in the order they are written in the code ?

Thanks.

Things are BUT you also have to make sure you let the main event loop get some time so the UI can be redrawn/refreshed
Your loop blocks that from happening

How is the loop blocking something that should have happened BEFORE the loop ?

Interface updates happen at the end of a method. If you put a thread blocking (your loop is on the main thread) loop you’re going to block interface updates until the end of the loop.

Instead of using a loop to check the thread status, use a timer with 250ms delay. In the Action event, check the thread status, if it’s done hide the please wait window.

[quote=298737:@Tim Parnell]Interface updates happen at the end of a method. If you put a thread blocking (your loop is on the main thread) loop you’re going to block interface updates until the end of the loop.
.[/quote]

THIS is what I was missing.
Thanks for the quick replies. This forum is gold as usual

I used Window.Refresh I hope it’s a good alternative to the timers.
It works fine.

Not the best solution, the loop will lock up the app even though you’re doing your processing in a thread because the loop is still on the main thread. Windows will change the title bar to (Not Responding…) and Mac will show the beachball until the end of the loop.

Loops are a very bad programming style. They consume the CPU and freeze execution. They should be replaced by timers.

"Order of executions" caused “Executions will continue until morale improves” to pop into my head

A better approach would be to make the splash screen the default window of the app and Show() the main window from the splash screen. Put your long process into a thread that runs on the splash screen and at the end of the thread, signal that it is time to load the main window. Have a timer running on the splash screen that looks for that signal and shows the main window (and closes the splash screen).