0

I have my ViewModel with an ObservableCollection

private ObservableCollection<ObjectView> _elementList;
public ObservableCollection<ObjectView> ElementList
{
    get { return _elementList; }
    set { _elementList = value; RaisePropertyChanged("ElementList"); }
}

that is bind via an async thread when from TableView it's called a ReloadData (that is to have an endlessscroll on my TableView). I have noticed this error (that some time, not always, make it crash my app):

Feb 28 10:14:25 iPhone-di-Luigi JRUITouch[4518] <Warning>: CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
0   QuartzCore                          0x31ce00a5 <redacted> + 268
1   QuartzCore                          0x31cdff59 <redacted> + 224
2   QuartzCore                          0x31ce05bb <redacted> + 30
3   QuartzCore                          0x31ce1f6b <redacted> + 158
4   QuartzCore                          0x31ce546d <redacted> + 40
5   UIKit                               0x3219a2c5 <redacted> + 48
6   UIKit                               0x321d0c65 <redacted> + 460
7   UIKit                               0x321d0a45 <redacted> + 68
8   CoreFoundation                      0x2f8240f3 <redacted> + 90
9   CoreFoundation                      0x2f824003 <redacted> + 198
10  UIKit                               0x3213a825 <redacted> + 628
11  LSUITouch                           0x001a24ec wrapper_managed_to_native_MonoTouch_ObjCRuntime_Messaging_void_objc_msgSend_intptr_intptr + 100
12  LSUITouch                           0x0017b948 MonoTouch_UIKit_UITableView_ReloadData + 52
13  LSUITouch                           0x00a210d4 Cirrious_MvvmCross_Binding_Touch_Views_MvxBaseTableViewSource_ReloadTableData + 176
14  LSUITouch                           0x00a24cf0 Cirrious_MvvmCross_Binding_Touch_Views_MvxTableViewSource_CollectionChangedOnCollectionChanged_object_System_Collections_Specialized_NotifyCollectionChangedEventArgs + 248

someone have an idea how to fix?

Luigi Saggese
  • 5,299
  • 3
  • 43
  • 94
  • Where is the code that does ReloadData? Is it adding to the Colleciton on a background thread? See http://stackoverflow.com/questions/2104614/updating-an-observablecollection-in-a-separate-thread and lots of other questions on that – Stuart Feb 28 '14 at 10:00
  • If you weren't using Mono I'm pretty sure that error message provides some information about a debug flag to enable to get logging to help you track down this issue. There it's called `CA_DEBUG_TRANSACTIONS` and you set it to `1` as an environmental variable. Maybe you can see if there is something similar in Mono? – David Rönnqvist Feb 28 '14 at 10:04
  • @DavidRönnqvist i had to set `CA_DEBUG_TRANSACTIONS=1` to see that log... – Luigi Saggese Feb 28 '14 at 10:23
  • @Stuart ReloadData it's a method on TableView...yes i'm adding elements on Collection and to avoid `IllegalCrossThreadCall` i have set `UIApplication.CheckForIllegalCrossThreadCalls = false;` – Luigi Saggese Feb 28 '14 at 10:25
  • You might be better now making the cross thread calls, rather than just turning the checking off... the warnings are there for a reason - e.g. https://www.youtube.com/watch?v=KQOZBdGLxKQ – Stuart Feb 28 '14 at 10:27
  • Then do you suggest to implement `AsyncObservableCollection`? – Luigi Saggese Feb 28 '14 at 10:46
  • @Stuart i have tested also using `AsyncObservableCollection` but warning it's always same... – Luigi Saggese Feb 28 '14 at 18:26

1 Answers1

1

Problem resolved via Stuart suggestion.

Update UI from outside threads it'll be dangerous...you could be some unexpected effects. Then each time that i add elements on my ObservableCollection i have called this update on main thread in that way:

private void AddElementsOnMainThread(AdvertObjectView item){
            MvxMainThreadDispatcher.Instance.RequestMainThreadAction((Action)delegate(){ 
                ElementList.Add(item);
            });
        }

in that way i have no more that warning and my UI thread it's protected from unexpected surprise!

Luigi Saggese
  • 5,299
  • 3
  • 43
  • 94