Hello,

Thank you Jens Alfke, Peter Burtis and Stephen Joseph Butler for your excellent, quick and helpful replies.

Thank you Jens for the heads up about the threading and for letting me know that things are done this way in Cocoa -- I just didn't want to be out in left field.

Below. for future searchers, are three techniques for sleeping 0.1 seconds. Please excuse my naive use of the phrase 'current thread'.

These two techniques don't require splitting your method into 'before' and 'after' parts. Downside is that they will stop all activity in the current thread:

    NSDate *future = [NSDate dateWithTimeIntervalSinceNow: 0.1];
    [NSThread sleepUntilDate:future];

    usleep(100000)  // sleep 1/10 second, 10K microseconds

This one is neat since it uses a 'behind the scenes' timer. Downside is that it requires 'splitting' your method into 'before' and 'after' parts. However, it is best if you are waiting for some process to finish that is running in the current thread:

[self performSelector: methodName withObject: nil afterDelay: 0.1]; // uses behind the scenes timer

Stephen's technique has neither downside. It works perfectly but I confess I'm nervous about releasing it to my client:

call

    NSDate *future = [NSDate dateWithTimeIntervalSinceNow: 0.1];
    [[NSRunLoop currentRunLoop] runUntilDate: future];

from your method. Stephen warns that the host method needs to be re-entrant or guard against multiple entries.

Thanks and best regards to all,

Steve



Original message

how do I delay, wait, pause for a tenth of a second?

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.

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.

delay
wait
pause
sleep

_______________________________________________

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