• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Stalling until notification is received
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stalling until notification is received


  • Subject: Re: Stalling until notification is received
  • From: Ken Thomases <email@hidden>
  • Date: Tue, 31 May 2011 09:47:02 -0500

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 (email@hidden)

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:

This email sent to email@hidden

References: 
 >Stalling until notification is received (From: Indragie Karunaratne <email@hidden>)

  • Prev by Date: Stalling until notification is received
  • Next by Date: How can I work with code completion in Xcode 4?
  • Previous by thread: Stalling until notification is received
  • Next by thread: How can I work with code completion in Xcode 4?
  • Index(es):
    • Date
    • Thread