NSManagedObjectContextObjectsDidChangeNotification not posted automatically
NSManagedObjectContextObjectsDidChangeNotification not posted automatically
- Subject: NSManagedObjectContextObjectsDidChangeNotification not posted automatically
- From: Jakob Olesen <email@hidden>
- Date: Fri, 8 Sep 2006 23:32:31 +0200
I have a Core Data application with three threads. They have a
NSManagedObjectContext each and a shared
NSPersistentStoreCoordinator. One thread is running [NSApplication
main], the other two in [[NSRunLoop currentRunLoop] run].
Sometimes, after making changes to an object,
NSManagedObjectContextObjectsDidChangeNotification is not posted
automatically.
In the main (GUI) thread, the notification is posted as soon as I
move the mouse, so that is not so bad. That method doesn't work in
the background threads, though.
One background thread is working fine. This thread is doing
networking with NSURLConnection, and it looks like the notification
gets posted each time around the run loop. No problems.
The other background thread is just doing calculations. Here the
notification is often not posted at all, even with several thousand
pending changes, and an idle run loop. I set up a repeating NSTimer
with a do-nothing selector to try to trigger the run loop into
delivering idle notifications of whatever Core Data is using
internally. Doesn't work. Timer selector gets called just fine. No
notification. Then I put in [moc processPendingChanges] in the timer
callback. This triggers the notification.
So calling [moc processPendingChanges] from an NSTimer works, but it
is not an ideal solution. I would prefer to see the notification as
soon as the run loop is idle. I also don't like the idea of a
constantly running timer, forcing part of the application to be in
resident memory constantly.
What triggers Core Data to call -[processPendingChanges] internally?
Apparently mouse events in the main thread. Maybe something that
NSURLConnection is doing. Not an NSTimer. Not CFRunLoopSourceSignal()
+CFRunLoopWakeUp() (I use that for inter-thread comms).
Is there some kind of voodoo I can do to my thread to wake up Core
Data, or should I figure out a way of calling -
[processPendingChanges] myself?
_______________________________________________
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