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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to