Re: Preventing beach balls
Re: Preventing beach balls
- Subject: Re: Preventing beach balls
- From: Uli Kusterer <email@hidden>
- Date: Mon, 19 Feb 2007 22:36:40 +0100
Am 19.02.2007 um 02:03 schrieb Paul Borokhov:
I'm trying to find a relatively _easy_ solution to prevent
beachballing in my application. I did take a look at threading, but
all of the provided examples seem to imply inter-object
communication with ports and proxies, whereas I don't need anything
near as complicated in my application. I just want to be able to
execute [self foo] and yet leave the interface responsive at all
times. All I need is something like (oneway void), but that has no
effect on calls made by the object to itself...so, any other
solutions?
You could also do a queue: Use performSelector:...withDelay:0 to
request a slice of processing time in the event loop, do one small
subtask from your queue in your selector, then use
performSelector:withDelay: again to request more time after you've
returned control to the main event loop.
You could also use a timer, but those are really more intended to be
used when you need to have gaps between your processing.
Or you could go down and ugly into low-level thread stuff and put
your second thread in the same group as the main thread so they block
each other, and then just occasionally sleep() to yield to the main
thread to keep things responsive.
Or you can run your own event loop occasionally using NSApplication's
nextEventMatchingMask:... and sendEvent:... process some data, and
call those two periodically to handle a few events, then process some
more data... This second approach is kinda dangerous though if you're
not showing a modal panel, because the user could start the same
operation again and you'd have the second sub-event-loop blocking the
first sub-event-loop which blocks the main-event-loop.
Ideally, you'd use a second thread that just does its thing
completely insulated from the main thread (or maybe with
performSelectorOnMainThread:waitUntilDone: as the only point where
objects on the main thread are selectively accessed), it really is
the least troublesome solution unless your work fits very well in
above-mentioned queue approach.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden