On 24 May '08, at 11:45 PM, Steve Steinitz wrote:
I don't want to use NSTimer because I just want to resume where I left off. I don't want to be in a tight loop because I need the system to finish something. I just want to pause execution for a short time. I think there was a wait() in OS9. I found a wait() in wait.h but it wants an int * and made me nervous.
usleep( ) is the basic call. The parameter is in microseconds, so usleep(100000) would sleep 1/10 second.
Specifically, when I send a fetch message to an NSArrayController, it sometimes takes a fraction of a second for its selection to become valid. Currently I fire an NSTimer to call a 'part 2' method to finish what I am doing (scrolling the selection into view), but it lacks niceness.
The problem is, if your thread is sleeping, who's updating the array controller? Unless you know that it's somehow happening on a background thread (and that doesn't seem likely), the sleep isn't going to do any good.
A simpler alternative to using a timer is to call [self performSelector:withObject:afterDelay:]. It uses a temporary timer behind the scenes, but is easier to call. I know what you mean about the annoyance of having to deal with asynchrony by breaking your code up into pieces, but that's basically the way things are done in Cocoa. (I've given some thought to using exotic techniques like coroutines to get around this, but it appears they'd seriously confuse the Obj-C runtime.)
—Jens
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ 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]