Reputation: 571
I have a refresh process that runs in the background (just using performInBackground is all) and part of that has db updates so I have a separate MOC for the background thread. I then use the didSave notification to merge in the changes to the main MOC. While the app is refreshing in background, the user can click around the UI.
Mostly works, but i'm seeing some locks every now and then. When I look at the method called before the lock, its something that accesses the main MOC. Nothing in my refresh process accesses this, everything accesses a background MOC. BUT, I was thinking that the changes i make to the background MOC do get merged using the didSave notification. If I try to query one MOC while its doing mergeChangesFromContextDidSaveNotification, would that be the issue? What's the best way around this? I thought I had solved my db issues with a separate MOC for my background thread, but the merge is gonna be an issue right?
Upvotes: 0
Views: 92
Reputation: 939
You are on the right track. Each thread using its own MOC; and main UI thread getting notifications when background thread updates the data. There is nothing in what you describe that can result in a lock. The locks you experience are most likely a result of long running code executing in the main thread, blocking the UI, while you think this processing is being done in a background thread.
Upvotes: 1