Hi, I’m going to make some assumptions since I don’t have a full picture of your code. Please, correct anything wrong.
Given that you’re trying to use AsyncContext I’m going to assume that the code you posted isn’t running on a thread with a synchronisation context (like a main or ui thread).
The problem with your code is that using AsyncContext.Run like you did runs realm.Refresh() on a different thread every iteration of the loop. Because a realm instance can’t be shared with multiple threads, you should get an exception.
In order to achieve what you’re trying to do, you could do something like:
In this way you are calling realm.Refresh() on the same thread were you subscribed for notifications.
As a side note when you are on a the main/UI thread, you always have a synchronisation context. This allows realm to be able to queue its own refresh without the need for the user to do so. Hence, in that case the following would just work:
In fact I didn’t get such exception when running my code. Anyway, I tried your code but still no luck.
Instead, I found something else. From my machine 2, I executed a program that updates and commits Person.Fullname periodically. At the same time in machine 1, I executed another program that pick the same Person object (using realm.Find()) and print out its Fullname, also periodically.
The result is the Fullname was not changed in machine 1.
=>That means data was not synced in real-time???
About Realms.Server.RegexNotificationHandler, it’s from Legacy Realm. I used it to listen to data changes from Realm Cloud. And what I’m trying to do in this topic is to archive the same.
For me to properly help you I’d need to take a look at the full code of the 2 examples. Could it be possible for you to share both projects with me? You could send it by email to
andrea [dot] catalini [at] mongodb [dot] com
If there is something sensitive in those examples then I can supply you with a link to securely upload the them.
Hello, I have the same problem. SubscribeForNotifications function doesn’t firing in .NET app. It worked with the Legacy Realm but it is not working now. I’m using 10.3.0 Realm version and .NET 4.8.
As you could see from the conversation above, in order for me to help I need to see a lot more of your code and have details on the type of application you’re working on, specifically what thread the code is executed on and if it has a synchronization context.
There is always a SynchronizationContext in any .NET application, regardless of the framework that you’re using. The only difference is that each .NET framework has a different implementation of SynchronizationContext. For example Windows Forms always installs a WindowsFormsSynchronizationContext on the thread on which the first form is created. (This thread is commonly called “the UI thread”.)
If you want to have a more in-depth reading on the subject, this blogpost from Microsoft is a good place to start.
Back to your problem. As explained in our documentation, once you’ve subscribed for notifications on your realm instance, you can only get notifications if this instance of realm is regularly refreshed. The SDK makes this happen automatically on the Main thread, but it’s on the user to refresh the realm subscribed to, if such realm is open on a background thread.
So, is your realm opened on the main thread? I guess yes. Where and when are you calling GetOrLoginUser and OpenRealm? All these questions could simply be answered if you could share your project, so that I can take a look at it and see what’s going on.
You can email it to me at
andrea [dot] catalini [at] mongodb [dot] com
or if there is something sensitive (like it’s not a POC) then I can supply you with a link to securely upload it.