• 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: updating NSView on separate thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: updating NSView on separate thread


  • Subject: Re: updating NSView on separate thread
  • From: Jens Alfke <email@hidden>
  • Date: Mon, 1 Feb 2010 08:57:24 -0800

On Feb 1, 2010, at 7:20 AM, Kyle Sluder wrote:

> So in your override of -writeToURL:…, spin off the background thread like I suggested, then set up your UI, and then start running the runloop in a special modal mode until your background thread is done.

Nested runloops like this are usually a "code smell", an indication that you're trying to shoehorn asynchronous code into a synchronous caller, and should instead refactor the calling code to be async too. However, if you're implementing NSDocument's abstract save functionality, you can't do a lot about that.

Pay attention to Kyle's advice to use "a special modal mode". If you run the runloop in a normal mode, then your app can handle incoming events while in this loop and dispatch them to your code — this often leads to unexpected re-entrancy that can cause bizarre and hard-to-debug problems. (It's happened to me more than once.) Nowadays I always make sure that, if I have to use a nested runloop, I make up my own unique mode name to run it in.

(BTW, it seems a little odd to me that it takes so long to save documents in your app. Have you tried profiling your save implementation to see if it can be made faster? Most apps save nearly instantaneously.)

—Jens_______________________________________________

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

  • Follow-Ups:
    • Re: updating NSView on separate thread
      • From: Corbin Dunn <email@hidden>
References: 
 >Re: updating NSView on separate thread (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: convert password from SecKeychainFindGenericPassword to NSString
  • Next by Date: Re: Tutorial for writing a bindings-compliant NSView subclass?
  • Previous by thread: Re: updating NSView on separate thread
  • Next by thread: Re: updating NSView on separate thread
  • Index(es):
    • Date
    • Thread