Re: NSTask dilema...
Re: NSTask dilema...
- Subject: Re: NSTask dilema...
- From: Sherm Pendley <email@hidden>
- Date: Wed, 31 Mar 2010 14:48:40 -0400
On Wed, Mar 31, 2010 at 2:21 PM, Jean-Nicolas Jolivet
<email@hidden> wrote:
> I have to run a bunch of NSTasks and I'm not sure to proceed considering I want to be able to update the UI when a task is completed, and I want the process to be as fast as possible (obviously)...
>
> So far I tried a couple of ideas but they all had their problems:
>
> - I tried launching the tasks on the main thread but it locks up my UI and I can't update my progress bar...
NSTask doesn't block unless you specifically ask it to, by calling
-waitUntilExit.
> So I guess my question is... if using threads prevents me from using waitUntilExit
It doesn't normally prevent that. In fact, in most cases you'd only
want to use it from a background thread, because using it from the
main thread would block the main event loop and trigger a beach ball.
> ... and launching them on the main thread locks up my UI... is there anything I am missing?
What you're missing is that NSTask doesn't (normally) block the UI
thread, and that calling -waitUntilExit doesn't (normally) cause a
crash when called from a secondary thread.
> Any help would be appreciated
Just launch your NSTask on the main thread, and *don't* call
-waitUntilExit. Listen for NSTaskDidTerminateNotification, and respond
to it by updating your UI.
sherm--
--
Cocoa programming in Perl:
http://www.camelbones.org
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden