Discussion:
Delayed perform never performing
James Walker
2018-08-24 18:21:01 UTC
Permalink
What could cause a delayed perform (using -[NSObject performSelector:
withObject: afterDelay:]) to never happen? The requested delay is
0.175. I've checked that it's being issued from the main thread, and
I've checked that cancelPreviousPerformRequestsWithTarget: is not being
called. I wondered if I needed to do the delayed perform in a
particular run loop mode, and found that [[NSRunLoop currentRunLoop]
currentMode] is nil, which seems odd. Why would the run loop not be
running?
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive.net
James Walker
2018-08-24 20:09:30 UTC
Permalink
withObject: afterDelay:]) to never happen?  The requested delay is
0.175. I've checked that it's being issued from the main thread, and
I've checked that cancelPreviousPerformRequestsWithTarget: is not being
called.  I wondered if I needed to do the delayed perform in a
particular run loop mode, and found that [[NSRunLoop currentRunLoop]
currentMode] is nil, which seems odd.  Why would the run loop not be
running?
Never mind, I figured it out. I had to add inModes:
@[NSModalPanelRunLoopMode]. The code had been working when my
formerly-Carbon app was using RunApplicationEventLoop, but now that I've
switched
to NSApplicationMain, apparently modal loops have started using
NSModalPanelRunLoopMode.
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net
Andy Lee
2018-08-24 21:36:41 UTC
Permalink
What could cause a delayed perform (using -[NSObject performSelector: withObject: afterDelay:]) to never happen?
I'm sure you've checked, but *just in case*, I'll ask: are you sure you're not sending it to nil?
I wondered if I needed to do the delayed perform in a particular run loop mode, and found that [[NSRunLoop currentRunLoop] currentMode] is nil, which seems odd. Why would the run loop not be running?
Where are you checking currentMode? I did a quick test and noticed currentMode is nil in my app delegate's applicationDidFinishLaunching: method (I guess because the run loop hasn't started yet?), but it's non-nil a little later when my delayed perform is called.

My delayed perform "works for me", so I'm afraid I don't have much to suggest regarding that.

- (void)fire:(id)arg {
NSLog(@"FIRED -- current run loop mode: %@",
[[NSRunLoop currentRunLoop] currentMode]);
NSLog(@"%@", @"You're fired!");
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLog(@"Did launch -- current run loop mode: %@",
[[NSRunLoop currentRunLoop] currentMode]);
[self performSelector:@selector(fire:)
withObject:nil
afterDelay:0.175];
}

Output:

2018-08-24 17:34:18.852033-0400 Scratchy[94529:13604294] Did launch -- current run loop mode: (null)
2018-08-24 17:34:19.035517-0400 Scratchy[94529:13604294] FIRED -- current run loop mode: kCFRunLoopDefaultMode
2018-08-24 17:34:19.038105-0400 Scratchy[94529:13604294] You're fired!

--Andy

_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive.net

Continue reading on narkive:
Loading...