• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTimer not firing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSTimer not firing (From: email@hidden)
 >Re: NSTimer not firing (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: [iPhone 3.0] correct way to release a UIImageView flip animation?
  • Next by Date: Color with pattern image
  • Previous by thread: Re: NSTimer not firing
  • Next by thread: Color with pattern image
  • Index(es):
    • Date
    • Thread