Hi Andrea.
The UI thread lags because in cases that there is no internet connection I need to use the synchronous GetInstance()
to open the realm as the GetInstanceAsync()
method doesn’t work offline. My _realmService.GetInstanceAsync()
is as follows:
public async Task<Realm> GetInstanceAsync()
{
try
{
SyncConfiguration config = new SyncConfiguration("Scribetech", _realmUser);
return Connectivity.NetworkAccess == NetworkAccess.Internet ? await Realm.GetInstanceAsync(config) : Realm.GetInstance(config);
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
Debug.WriteLine("RealmService.GetInstanceAsync: " + ex.InnerException.Message);
}
else
{
Debug.WriteLine("RealmService.GetInstanceAsync: " + ex.Message);
}
return null;
}
}
I call the ListenForRealmChanges
when I log in, from a command as follows:
public Command LoginCommand
{
get
{
return new Command(async () => {
<!-- Logic for signing in the user --!>
await _updaterService.ListenForRealmChanges();
});
}
I thought the point of the AsyncContext
was to enable the realm to run on the background? I haven’t been able to find any examples of it being used with realm so I have previously tried wrapping the ListenForRealmChanges
method in an AsyncContext
but that doesn’t seem to do anything.