• 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: Stopping a NSRunLoop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stopping a NSRunLoop


  • Subject: Re: Stopping a NSRunLoop
  • From: Andrei Tchijov <email@hidden>
  • Date: Tue, 23 May 2006 16:40:04 -0400

I am not sure that your statement about "configureAsServer" is 100% correct. In my case when run loop "primed" with "configureAsServer", "run" method will "run forever", otherwise it will exit immediately. So I guess it does change something (application in question used to intercept NSWorkspace notifications and forward them to server background process. All it does is register bunch of addObserver:selector:name:object: and invoke configureAsServer ).

I do appreciate that my solution is "sub-par", but as I mentioned before, this is best I could google and it works.

Andrei

P.S. while writing response, I realized that in my particular case, I can just call "exit()" in response to NSWorkspaceWillPowerOffNotification, so it should be OK for me to use "endless" "run" on NSRunLoop. Thanks for stimulating my brain :-)

On May 23, 2006, at 4:18 PM, Bill Bumgarner wrote:

On May 23, 2006, at 12:49 PM, Andrei Tchijov wrote:

I guess if you can "remove" all sources from RunLopp ... but than it should stop by itself without CFRunLoopStop ... In my case I needed to stop RunLoop which was "primed" like this

[[NSRunLoop currentRunLoop] configureAsServer];

combination of getCFRunLoop and CFRunLoopStop did not work, so I end-up using Apple example

double resolution = 1.0;
BOOL isRunning;
do {
NSDate* next = [NSDate dateWithTimeIntervalSinceNow:resolution];
isRunning = [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:next];
} while (isRunning && !endRunLoop);


works great.

You really don't want to do that -- it'll make your loop "busy wait". That is, it is going to wake up and do something every second, regardless of whether or not it has anything to do. If the enclosing app has been hidden, this is going to cause the app to wake up, consume memory resources that could otherwise be devoted to what the user is really focused on.


-configureAsServer does absolutely nothing. Zero. Nada. Zilch. Total no-op.

As per the documentation (for the -run method), your run loop will stop running once all input sources have been invalidated. Figure out how to get a hold of and invalidate the input sources as necessary. That way, your run loop will consume no cycles and minimal resources when there is no work to be done.

b.bum

_______________________________________________ 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: Stopping a NSRunLoop
      • From: Bill Bumgarner <email@hidden>
References: 
 >Stopping a NSRunLoop (From: Rob Crawford <email@hidden>)
 >Re: Stopping a NSRunLoop (From: "Shawn Erickson" <email@hidden>)
 >Re: Stopping a NSRunLoop (From: Andrei Tchijov <email@hidden>)
 >Re: Stopping a NSRunLoop (From: Mike Blaguszewski <email@hidden>)
 >Re: Stopping a NSRunLoop (From: Andrei Tchijov <email@hidden>)
 >Re: Stopping a NSRunLoop (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: RE: Stopping a NSRunLoop
  • Next by Date: Re: Stopping a NSRunLoop
  • Previous by thread: Re: Stopping a NSRunLoop
  • Next by thread: Re: Stopping a NSRunLoop
  • Index(es):
    • Date
    • Thread