Freezing up interface during CPU intense operations...

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Freezing up interface during CPU intense operations...

Post by Garrett » Mon Sep 21, 2009 5:39 am

Ok, I have the indexing of my offline wikipedia project going, but I noticed one issue while continuing to work on that bit. That is that the interface freezes up while this process takes place. You can't move the stack/window at all during this time, plus, if you open other windows on top of it, the interface turns white and does not refresh, except for objects that I am updating during this process.

Is there any way to keep this from happening?

Thanks,
~Garrett
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon Sep 21, 2009 6:19 am

The 'best' way is to chop up the data processing into chunks that are executed using a 'send in time' construct - this way, your user interface won't be blocked and you could even add a 'Cancel' button.
Another method is to sprinkle your code with 'wait 0 milliseconds' as this gives the engine 'breathing room' to refresh the screen inside tight loops - but your user still won't be able to cancel out of the operation.
Something in between these two methods is putting 'wait 0 milliseconds with messages' in strategic spots of your processing code: this allows the engine to temporarily halt the execution of your script, handle the next user input event and then resume the execution of your script.
It is probably a good idea to show a progress indicator if possible while a long-running process is busy; and if you're going to allow user interaction during the process, then disable certain controls to prevent the user from starting multiple tasks that may interfere with one another.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Mon Sep 21, 2009 4:44 pm

Thanks Jan. I had just added a progress bar and a field showing elapsed time yesterday. I'll put the "wait 0 milliseconds" back in.
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Tue Sep 22, 2009 6:10 am

Works like a Gem, thanks Jan :-)
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)

Post Reply