Re: Secondary run loops?
Re: Secondary run loops?
- Subject: Re: Secondary run loops?
- From: Justin Anderson <email@hidden>
- Date: Thu, 10 Aug 2006 00:47:53 -0400
I'd personally recommend spawning a new thread, but if you're just
interested in a specific UI element like a progress bar, you also
have the option of forcibly redrawing it by calling [theProgressBar
displayIfNeeded] once in a while in your loop -- say every iteration
0.25 or more seconds since it was last drawn.
The drawback to this is that there's no way for the user to click a
cancel button while this is happening, and the spinning beach ball
will appear if this takes longer than a few seconds.
Justin
On Aug 9, 2006, at 11:28 PM, Mark Dawson wrote:
I'm not as famailiar with run loops in Cocoa and how they work.
Here's my problem:
If I have a "start" button and the user presses it, my action gets
called. If I do "stuff" within that call (posting notifications,
etc), it's still happens relative to that call, so the UI isn't
being updated.
What I would have done in (old, not sure about new) Carbon would be
(pseudo code):
while !done
do_something(); // the actual work; could be a thread
while WaitNextEvent() && !quit() && !processDone()
updateProgressBar(); // UI is active, stop if user has
pressed "stop" button or thread has finished
This would have been called from the "start" event message (i.e.,
nested WaitNextEvents).
What's the best way to do this in Cocoa? What I'm really not sure
is how to let events happen while I'm in my loop?
Thanks!
mark
_______________________________________________
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