Re: Preventing beach balls
Re: Preventing beach balls
- Subject: Re: Preventing beach balls
- From: "Jim Thomason" <email@hidden>
- Date: Sun, 18 Feb 2007 19:14:16 -0600
Threads. You want threads. But you don't need ports or proxies or
anything. I wonder if you were reading about distributed objects,
which would start wanting those things. Distributed objects is easy,
too, and can be used for communication between threads as well as
between processes (and machines!), but it's overkill if you don't
actually need it. It is really cool and easy technology, though.
An easy approach is to start up a new thread when you want to do the action.
Instead of [self foo], you'd have something like:
[NSThread detachNewThreadSelector:@selector(runFooInThread:)
toTarget:self withObject:nil];
then:
-(void) runFooInThread:(id) object {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[self foo];
[pool release];
}
It may be keen to somehow add code to the foo method (if you can) to
allow it to be canceled by the user. Otherwise you'll prevent the
beachball, but the user won't be able to stop it regardless.
Note - some things (mainly involving UI, but there are others) must be
done on the main thread.
performSelectorOnMainThread:withObject:waitUntilDone: is your friend
here.
It's really quite easy.
-Jim.....
On 2/18/07, Paul Borokhov <email@hidden> wrote:
Hi all,
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?
Thanks!
Paul
_______________________________________________
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
_______________________________________________
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