Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

UIKit Consistency error using Akavache Sqlite in Xamarin.Forms

I'm getting this error when I use Akavache's GetAndFetchLatest:

UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.

It seems to only have started when I added the Akavache Sqlite linker override files.

Anyone have a clue why this would happen?

Linker File:

using System;
using Akavache.Sqlite3;

// Note: This class file is *required* for iOS to work correctly, and is 
// also a good idea for Android if you enable "Link All Assemblies".
namespace MyApp
{
    [Preserve]
    public static class LinkerPreserve
    {
        static LinkerPreserve()
        {
            throw new Exception(typeof(SQLitePersistentBlobCache).FullName);
        }
    }


    public class PreserveAttribute : Attribute
    {
    }
}

Akavache Code Snippet:

var cache = BlobCache.LocalMachine;
var cachedPromise = cache.GetAndFetchLatest(
    "myitems",
    () => GetAllRemoteAsync(parameters),
    offset =>
    {
        TimeSpan elapsed = DateTimeOffset.Now - offset;
        var invalidateCache = (force || elapsed > new TimeSpan(hours: 0, minutes: 30, seconds: 0));
        return invalidateCache;
    });

cachedPromise.Subscribe(subscribedData => {
    response = subscribedData;
});

response = await cachedPromise.FirstOrDefaultAsync();

Answers

Sign In or Register to comment.