• 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
Preference Pane vs NSTimer/NSThread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Preference Pane vs NSTimer/NSThread


  • Subject: Preference Pane vs NSTimer/NSThread
  • From: Mike Kobb <email@hidden>
  • Date: Tue, 13 Jun 2006 18:39:44 -0700

Howdy,

As mentioned in a couple of other postings, I'm working on a System Preferences pane that controls a background server.

When certain settings change, I have to restart the server. I have to do this by signaling the server (good old fashioned SIGINT), waiting for it to stop, and then re-launching it. I do not have server source access to modify this sequence.

So, I wrote a little sheet that pops down on the preferences window that says (paraphrasing) "restarting, please wait a moment". I put that modal sheet on screen (attached to the window), message my server to shut down, and once it has shut down, I restart the server and take down that sheet.

So far so good.

Here's where it gets complicated. One of the places where I need to make this happen is when the user makes some changes in my panel, then quits System Preferences. In this case, I have to pop up a sheet that says "Apply changes?" (same as Apple's TCP/IP), and if they say yes, then I have to restart that server, which means I have to defer unselection of my panel until the restart has finished.

My shouldUnselect delegate method (sent to your NSPreferencePane subclass when you're being taken down) gets called when the app is trying to quit. I reply to the shouldUnselect with the NSUnselectLater response, put up my "apply changes?" sheet, and then call replyToShouldUnselect later on, when the restart process has concluded.

I have tried two approaches for waiting for the server to restart before calling replyToShouldUnselect. Both of them work fine when the user is simply switching panels in System Preferences, but NEITHER of them works at app-quit time.

At first, I set an NSTimer (with scheduledTimerWithTimeInterval) to fire every 1/2 second so that I could check that the server had stopped, before I started it again. This works great, except in the app-quit case, where scheduledTimerWithTimeInterval succeeds, but my timer never fires.

So, then I tried an NSThread (launched with detachNewThreadSelector), and had the thread post a notification when the server quit. This *also* works just fine, except at app-quit time, when the selector is never called.

I'm a bit flummoxed at this point. I can't understand why the thread, especially, doesn't seem to work in this circumstance.

Is there a well-known reason why a timer or a thread can't be started at the point where I *have* replied with NSUnselectLater, but have not yet called replyToShouldUnselect?

As noted before, I have also implemented a little "helper" app, and I'm leaning at this point towards asking the helper app to restart the server, but I thought I would post the question here first.

Thanks,
--Mike


_______________________________________________ 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
  • Follow-Ups:
    • Re: Preference Pane vs NSTimer/NSThread
      • From: Mike Kobb <email@hidden>
  • Prev by Date: Drawing text on top of a progress bar
  • Next by Date: Instant Messenger Framework finding current screen name
  • Previous by thread: Re: Drawing text on top of a progress bar
  • Next by thread: Re: Preference Pane vs NSTimer/NSThread
  • Index(es):
    • Date
    • Thread