Hey Jim -

The typical way that I like to handle this is with these methods from NSRunLoop.h:

@interface NSObject (NSDelayedPerforming)
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay inModes:(NSArray *)modes; - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay; + (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget selector: (SEL)aSelector object:(id)anArgument;
#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget;
#endif
@end

When something about your object changes that means it needs to recalculate its state in the future, I would note that the object has become invalid, and then schedule a callback in the future to validate the object. I would only schedule the call back if one wasn't already scheduled. If I needed to validate the object state immediately, I would cancel the callback and do immediate validation.

This is typically better than using a 0.5 second global timer because it won't fire when it isn't in use. Also, is the value 0.5 really special? You probably want to validate your objects at the end of the current event loop. You can easily do this by passing a value of 0.0 into 'afterDelay:'. The semantics for a delay of 0.0 might mean at the beginning of the next event loop, I'm not sure.

These after delay style messages can be easily abused and cause confusion in your program logic, so use them wisely.

Jon Hess

On Aug 5, 2008, at 7:16 PM, Jim Crafton wrote:

Is there a way to handle idle time in an NSApplication? In Win32 or
Carbon, since you manually write the actual while loop that processes
the events, this is pretty easy to do. Is there anything like this in
Cocoa? I've got some objects whose state (possibly) needs to be
updated, and I was planning on handling this in the "idle" handler.

My other idea, if this is not possible, would be to simply have a
timer that fires off every 0.5 seconds or so.

Thanks

Jim C
_______________________________________________

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/jhess%40apple.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to