Realm.GetInstanceAsync not Refresh

In .NET Asp Core Web App with Realm version 10.6.0 (but in previuos version too) GetInstanceAsync not refresh when other client change data and I call another Realm.GetInstanceAsync.
If I call refresh… it’s synch

var realm = await Realm.GetInstanceAsync(config);


This is covered in the documentation and there’s a section explaining how to use Realm in a console application. For self-sufficiency, the note in the docs says:

Notifications only work when your realm regularly refreshes. In the Main or UI thread of your application, realm refreshes happen automatically. On background threads, you need to handle this yourself by either calling Realm.Refresh() or installing a SynchronizationContext on the thread before opening the realm. The third-party library Nito.AsyncEx.Context provides a SynchronizationContext implementation and a convenient API to install it.

1 Like

Ok it’s clear, but when I call a second time GetInstanceAsync starts another thread why not synch?

Not sure I understand your question, can you clarify it and provide some code snippets outlining what you’re trying to achieve?

In a AspNet Core WebApp, in every method of controller I call this code to be sure I am in sync with other client before any query in realm:

            var app = Realms.Sync.App.Create(new AppConfiguration(myappid));
            var user = await app.LogInAsync(Credentials.Anonymous());
            var config = new SyncConfiguration(mypartition, user);
            var realm = await Realm.GetInstanceAsync(config);
            realm.Refresh(); // if I don't call this not sync change of other client
            var list = realm.All<.....>.....

Realm.GetInstanceAsync is not enough for sync, I have to call Refresh()

Okay, this looks like an issue that has been fixed in this PR and will be released with the next version of the SDK.

1 Like