Re: NSTimer not firing
Re: NSTimer not firing
- Subject: Re: NSTimer not firing
- From: Jerry Krinock <email@hidden>
- Date: Sun, 9 Aug 2009 14:15:31 -0700
On 2009 Aug 09, at 09:26, Alastair Houghton wrote:
I think the problem, therefore, is that you're trying to schedule
your timer
on the wrong thread (I guess you're expecting it to be scheduled on
your app's
main thread)?
The performSelectorOnMainThread::: methods are your friend in
situations like this. A cool thing I realized about these a few
months ago is that they are also NSOperation's friend, because you can
use them methods even if you ^are already^ on the main thread.
Invocations are even better, since you can get return values, and non-
object return values. But since I always forget how to make one, I've
written a little category on NSInvocation that makes it easy for me.
I use these liberally....
+ (NSInvocation*)invocationWithTarget:(id)target
selector:(SEL)selector
retainArguments:(BOOL)retainArguments
argumentAddresses:
(void*)firstArgumentAddress, ... ;
- (void)invokeOnMainThreadWaitUntilDone:(BOOL)waitUntilDone ;
+ (NSInvocation*)invokeOnMainThreadTarget:(id)target
selector:(SEL)selector
retainArguments:(BOOL)retainArguments
waitUntilDone:(BOOL)waitUntilDone
argumentAddresses:
(void*)firstArgumentAddress, ... ;
The trick is not to get deadlocks -- more than one operation waiting
on the main thread. The way to avoid that is to step back and make a
disciplined plan about what happens on what thread when.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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