iphone - Avoiding infinite recursion synching between multiple NSManagedObjectContexts -


Setup:

I have two managed reference sets (on the iPhone app) a main reference I For the most questions and background reference, I use it for long lasting work in the background.

I have setup notifications for NSManagedObjectContextDidSaveNotification against each managed object context. In response to the notification, I call the merge changelinksDidSwice notification to sync. It is also a necessity that at any time things should be changed in the main context, I need to run some jobs in the context of background, because things have changed now.

It works fine, as long as only typing in one of the references. In this case, writing on main context, however, if I write on background reference, then it causes infinite loop. Saving the background context triggers the information in the main context, which in turn merges into the changes and activates its information raised from the background context. It triggers background background for your background jobs, which (if they write something) start the cycle again.

It seems that this is a wrong setup, or I need to make some changes to the main reference "or background reference to read only at any time related to the" start "background. < / P>

Thoughts? Contrary to a specific "import-import-context-II" scenario, I believe that I need to keep my background context up to date in relation to the main context Is / whom I get the right results from my background job.

Looks like a design issue when you : You can find around it, you should consider avoiding the "permanent" background context. I usually recommend standing in the context of each operation (for which the NSO performs well) and then when they do one thing If it is complete, throw it away. Sync it. Switch to why many contexts avoids the need to because you need to update the main reference.

Do you think that you need a stable background context? If you have analyzed the cause performance?


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -