On Jun 7, 2012, at 4:51 AM, Patrick Robertson wrote:

> I seem to be having a problem with terminating apps and observing the
> 'terminated' property of NSRunningApplications. If you run my sample code
> (attached, and below), you will notice that even though Safari has quit
> (its icon has disappeared from the dock) the 'isTerminated' property
> returns NO indefinitely, causing my simple app to hang.
> 
> Am I missing something blindly obvious in my code, or is this a bug with
> the NSRunningApplication?
> I have tried this with different apps, not just Safari and I get the same
> result. In my own app, I'm using the
> runningApplicationsWithProcessIdentifier: method, but it doesn't make a
> difference.

https://developer.apple.com/library/mac/#documentation/AppKit/Reference/NSRunningApplication_Class/Reference/Reference.html

"Properties that vary over time are inherently race-prone. For example, a 
hidden app may unhide itself at any time. To ameliorate this, properties 
persist until the next turn of the main run loop in a common mode. For example, 
if you repeatedly poll an unhidden app for its hidden property without allowing 
the run loop to run, it will continue to return NO, even if the app hides, 
until the next turn of the run loop."

In your sample code, you're polling the property without allowing the main run 
loop to run. Given that your sample code is a Foundation tool, you don't 
automatically have a runloop created for you. If this is true of your actual 
code as well, you'll need to create a runloop and allow it to run (explicitly 
in your polling loop or rewriting your code to not synchronously block the 
thread).



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to