Re: Displaying progress of lengthy operation: complication with bindings and threads
Re: Displaying progress of lengthy operation: complication with bindings and threads
- Subject: Re: Displaying progress of lengthy operation: complication with bindings and threads
- From: PGM <email@hidden>
- Date: Fri, 31 Mar 2006 16:08:07 -0500
Sean,
In principle it is not really necessary to use a separate thread to
display a progress bar. You can just pop-up a modal window before
starting your lengthy calculations and while calculating every now and
then update the progressbar (every time go go through a loop for
example). The problem with that approach is however that you still get
the beachball and the user will not be able to press a Cancel button if
you have one.
If you do go for the multi-threaded option, in the new thread you
could use (immutable) copies of the connected model objects. Let the
new thread handle the lengthy calculations using those copies and let
it call "performSelectorOnMainThread" every once in a while not just to
update the progressbar, but also the original objects that are linked
to the GUI via bindings.
Unless the displayed user interface items are really important, it may
actually be easier to do all the updating only when your task is
finished. If I have a lengthy task running, I switch applications and
check my mail or something, and switch back when the task is done. I
guess that most users will be like me and will not just sit and watch
the UI of your program change while performing your calculations.
PGM
On Mar 31, 2006, at 1:50 PM, Sean McBride wrote:
Hi all,
Some operations in my app take several minutes and so the app currently
SPODs; I would prefer to add a progress bar. The app uses bindings and
is single threaded.
One idea is to spawn a worker thread to do the lengthy work like this:
for (num items)
lengthy computation
performSelectorOnMainThread:@selector(advanceProgBar:)
But the 'lengthy computation' part would read and write to my model
objects, and those objects are connected to UI objects via bindings.
I've searched the archives and this has been discussed before.
KVC/KVO/
bindings are not thread safe. Which- I believe, I'm no threading
expert- means it's entirely unsafe for my worker thread to touch any
object that is involved in bindings.
So now I'm really unsure of how to best approach this, any suggestions?
Thanks!
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden