Cannot update collection with Akavache

0

I'm write UWP app with MVVM, not Xamarin. This code throw System.Runtime.InteropServices.COMException exception on Tenders.Clear();

    public ObservableCollection<Tender> Tenders { get; set; }

    private void GetTendersFromCache()
    {
        Tenders = new ObservableCollection<Tender>();

        var cache = BlobCache.LocalMachine.GetAndFetchLatest("TendersResponse",
            async () => await _dataService.GetTenders());

        cache.Subscribe(cachedTenders =>
        {
            Tenders.Clear();
            foreach (var tender in cachedTenders)
            {
                Tenders.Add(tender);
            }
        });
    }

How can I update collection Tenders correctly?

Put this code into Dispatcher.InvokeAsync not help.

Exception info

An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.ni.dll but was not handled in user code Additional information: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

c#
uwp
win-universal-app
akavache
asked on Stack Overflow Nov 14, 2016 by Make Makeluv

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0