Closed pfedotovsky closed 4 years ago
Same here. It seems Realm.RealmChanged in not invoked.
Nito.AsyncEx
's AsyncContext
maintains its SynchronizationContext
for as long as the delegate passed to AsyncContext.Run
executes. In the example above the context ends immediately after subscribing to the Realm.Changed
event, so any notifications coming in aren't delivered because the SynchronizationContext
the realm instance was opened on no longer loops.
The simplest fix is to call SynchronizationContext.Current.OperationStarted()
as the last thing inside the AsyncContext.Run
delegate to prevent the context from exiting. When you need the context to exit call the OperationCompleted()
method.
In short, make sure to prolong the life of the AsyncContext
for as long as you need your realm objects to deliver notifications.
Goals
Get notifications when Realm is changed on the server (related issue https://github.com/realm/realm-dotnet/issues/1840)
I'm having hard time to undestand how to get notifications to work. The https://realm.io/docs/dotnet/latest/#notifications says that synchronization context must be installed (i.e. for Android). I've set up Nito.AsyncEx (see code below), but it isn't working. I haven't managed to find any code examples, it would be nice to see working sample.
Expected Results
RealmChanged event is triggered when Realm is changed
Actual Results
RealmChanged event is not triggered when Realm is changed
Steps to Reproduce
Code Sample
If I change FirstName in cloud realm, RealmChanged event is not triggered
Version of Realm and Tooling