On May 16, 2011, at 3:49 AM, Bing Li wrote:

>     - (void) Print
>     {
>         NSLog(@"I am doing a tough job!");
> //      [[[NSNotificationQueue alloc] 
> initWithNotificationCenter:[NSNotificationCenter defaultCenter]] 
> enqueueNotification: [NSNotification notificationWithName:@"Done" 
> object:self] postingStyle:NSPostNow]; // This is also sychronous.
>         [[[NSNotificationQueue alloc] 
> initWithNotificationCenter:[NSNotificationCenter defaultCenter]] 
> enqueueNotification: [NSNotification notificationWithName:@"Done" 
> object:self] postingStyle:NSPostWhenIdle];
>         NSLog(@"I need to leave!");
>     }
> 
> The commented line is the same as a synchronous notification. It works. But 
> the later line must be an asynchronous notification. However, the 
> AppController does not get notified. I don't understand what's wrong with the 
> code.

There is another current thread on this list ("NSPostWhenIdle not doing its 
job") which is also discussing NSNotificationQueue and how it works. You might 
refer to it for more information, including a link to one of Mike Ash's Friday 
Q&A blog entries on NSNotificationQueue: 
http://www.mikeash.com/pyblog/friday-qa-2010-01-08-nsnotificationqueue.html.

Since NSPostWhenIdle posts the event when the run loop is idle, the first 
question would be: do you have a runloop? Your original post included the 
following:

> In the main code, the above objects are utilized as follows.
> 
>    WorkingApp *app = [[WorkingApp alloc] init];
>    AppController *controller = [[AppController alloc] init];
> 
>    [app Print];
> 
>    char s[100];
>    scanf("%s", s);
>    [app release];
>    [controller release];

Which seems to indicate that you don't have a runloop in your sample code.


_______________________________________________

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