On May 31, 2011, at 9:03 AM, Indragie Karunaratne wrote: > I need to create a simple command line application that will stall (as in > keep running without exiting) until it receives a certain distributed > notification via NSDistributedNotificationCenter. What would be the best way > to go about doing this? I assume I'd have to have a separate thread for > observing the notification and then have some sort of loop running in main() > that checks whether the notification has been received, but I'm not certain. > Any tips would be appreciated.
Distributed notifications are received via a run loop source. So, you have to run the run loop in order for them to be received. Furthermore, the distributed notification center's run loop source is only registered into one run loop, the first to obtain it. Because the frameworks use distributed notifications themselves, this is pretty much required to be the main thread's run loop, even if you wanted to try to register it elsewhere. (They'd probably beat you to it, anyway.) So, just run the run loop in the main thread repeatedly. In your notification-handling method, set a flag that it was received. In your loop that keeps running the run loop, exit if that flag is set. Regards, Ken _______________________________________________ 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