Stopping an NSRunLoop OR getting NSDistributedNotificationCenter notifications
Stopping an NSRunLoop OR getting NSDistributedNotificationCenter notifications
- Subject: Stopping an NSRunLoop OR getting NSDistributedNotificationCenter notifications
- From: James Bucanek <email@hidden>
- Date: Sun, 18 Jun 2006 17:48:53 -0700
Greetings,
I've got a background daemon (Foundation command-line tool) that performs user-defined tasks at specific times.
I've never figured out how to get an NSRunLoop to exit in a timely fashion. All of the examples show how to "poll" the run loop, but I just found it offensive that a process that could be doing absolutely nothing for days is required to check if it should quit every second[1].
I thought I'd come up with an elegant solution, but now I think it's biting me. My main() starts a new thread that runs the application in a separate run loop. main() then suspends on an NSConditionalLock. When the daemon wants to quit, it simply changes the state of the lock and main() returns, instantly terminating the process.
Everything (NSConnections, notifications, timers, etc.) have been working gloriously -- except that I'm not getting any NSDistributedNotificationCenter notifications. I'm now pretty sure this is because NSDistributedNotificationCenter fires all notifications on the "main" run loop, which would be the run loop associated with the original thread, which is main(), which is permanently suspended on its NSConditionalLock.
So I'm looking for suggestions on how to
- Get an NSRunLoop to exit on demand
- Receive NSDistributedNotificationCenter notifications on a thread other than the one running main()
- Find some other way of terminating my application. I do realize that I could simply call exit(0), but I was just trying to engineer something a little more structured than that.
Thanks,
James
[1] My daemon has an odd requirement: If a newer version of the daemon is started, it contacts the existing daemon and tells it to terminate immediately. The new daemon can't initialize until the old one has terminated, so I can't afford long delays between deciding to exit and actually exiting.
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden