Dear Michael, You are right. There is no RunLoop in the code. Actually, although I have got to know the term, RunLoop, when starting to learn Cocoa for two months, until now I have not seen a sample code about RunLoop in any resources. So I don't know how to program with it.
I have one question. If I put the synchronous notification posts into a NSOperationQueue, it must also get asynchronous notification, right? Is the solution proper? Best regards, Bing On Mon, May 16, 2011 at 7:01 PM, Michael Babin <mba...@orderndev.com> wrote: > 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