site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type; bh=fTC1NXm0HSNlDsuqWPUbKxrERF3Sh6ZlWAzigyZPObo=; b=BokceTspVfXalGM7KUbZotRJz6BDME+rVAv0kRfQBBbKo1sM1xctB/BbA4exVTXAkl 7VuXgAwBTZr+EBRoMpdZ4zoSZ4fUsmMX6MbPLuu2gVctJiZc0No2MdMBN1k46cXrSUP9 KK/1RYB/fXTWiJFLz6piYes9mWpJsf9PES3BA= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=KjTHglVAi73QP7SRCoBwhDd4eyTeY646jh+r9DAN0qvMwuTxdsS3oIKxCvvf1Yd0oY PY8edkmSld/RsIdSpnx8kxEObwkEYE9fjGTOFV+BtBMJtGuIRO6MeP0VzOAI8TdMsufz VkhMaBvt94JY849+comG3rQiKw28q7NZzfHrc= On Wed, Mar 31, 2010 at 2:21 PM, Jean-Nicolas Jolivet <jeannicolascocoa@gmail.com> 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 (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: http://lists.apple.com/mailman/options/cocoa-dev/site_archiver%40lists.apple... This email sent to site_archiver@lists.apple.com