Re: Stopping a NSRunLoop
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