Tombstoning, Asynchronous Loading and Reference Types

Jan 24, 2011 at 9:02 PM

Hey all,

I'm running into a couple of different issues with tombstoning and collections bound to List Picker controls. I've developed some work around solutions for both of my problems but would love to hear other peoples input or if others have better solutions.

Issue: Asynchronous Load

Current my application loads some data required for the page from Isolated Storage, it does this asynchronously. When I tombstone the application and then resurrect it the OnActivate override triggers the load, then the tombstoned values are restored before the load is complete. This causes problems at a couple of levels, the first is that it overwrites the potentially changed values restored from the tombstone with the original value. The second is that we restore a selected item for our collection before the collection has been loaded from Isolated Storage. For the List Picker this is a real problem causing IndexOutOfRangeException. 

Current Solution

At the moment I have an boolean IsResurrected property that's set to true after a Load, given this value is restored before the asynchronous load is complete then I can check whether to use the original values or leave the restored values. This feels a little weak since it relies on timing of two threads.

Issue: Tombstoned Reference Types

Given the way Caliburn deals with with complex types in the tombstoning process can cause problems if you need to tombstone the Selected Item. What happens is that the restored value doesn't change the selected item property to the correct item. Instead it (correctly) overwrites the values of the selected item with the values of the previously selected item. This naturally leaves us with duplicate items in the collection.

Current Solution

At the moment for any given collection I'm storing as well the selected item but also the selected identifier (I update this when the select item changes). I now tombstone the identifier rather than the item. Then on resurrection after the asynchronous load is complete I select the item based on the identifier. Also considering using the index instead of the identifier.

Both of these solutions look to be working correctly (although there seems to be some issues updating the ListPicker off the UI thread), but seems quite a bit of pipeline code for what feels like it should be relatively easy.


Thoughts? Comments? Suggestion?