Re: Core Data: Progress bar using Sheet, modifying context in thread
Re: Core Data: Progress bar using Sheet, modifying context in thread
- Subject: Re: Core Data: Progress bar using Sheet, modifying context in thread
- From: Chris Suter <email@hidden>
- Date: Sat, 5 Aug 2006 11:22:15 +1000
On 04/08/2006, at 7:45 PM, Jakob Olesen wrote:
On 04/08/2006, at 6.05, Bill Coleman wrote:
Question 1: I'd like the import or export process to be document-
modal, with the progress of the operation displayed in a sheet.
This is a little tricky, since once you call beginSheet:
modalForWindow: ..., you can't do any more processing. So, to
perform the actual operation, I first start an NSThread. Getting
it to quit properly was tricky, as you have to use
performSelectorOnMainThread: to get the endSheet: call to work.
My question is -- is this the right way to do this? Is there a
better way? It seems to be fraught with problems.
You should try to avoid using a thread for something like this.
Most classes in AppKit are not thread safe, so you should only
touch them in the main thread. This goes for NSManagedObjectContext
and NSManagedObject as well.
Read the Core Data documentation on multithreading, but really, try
to avoid threads.
I disagree. Really the only way to do this is to use a separate
thread. It's true that most classes aren't thread safe, but there's
no need to be accessing objects in different threads at the same time.
The import should load into new temporary objects and then switched
over in the main thread upon completion. Progress information can be
conveyed either by using performSelectorOnMainThread:... or a
periodic timer on the main thread.
- Chris
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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