Realm Transaction in Xamarin #3335
-
I am using Realm .Net SDK 11.0.0 with latest Xamarin forms framework We are saving data to realm db and it is working fine but for few cases when call is coming from different threads or schedulers then it is throwing exception "can not modify ...... outside write transaction:
In the above code, it always go to line 4 as it finds IsIntransaction true and then throws exception Here is stack trace
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hm, I can see that we're not checking the thread in
While the error message is misleading, this wouldn't have worked in any case since you cannot access a Realm instance from multiple threads. So you should review your architecture and make sure to reopen the Realm instance on each thread/scheduler. |
Beta Was this translation helpful? Give feedback.
Hm, I can see that we're not checking the thread in
IsInTransaction
, which may explain the issue that you're seeing. Essentially, what I believe is happening is:AddItem
on thread B.realm.IsInTransaction
returnstrue
.While the error message is misleading, this wouldn't have worked in any case since you cannot access a Realm instance from multiple threads. So you should review your architecture and make sure to reopen the Realm instance on each thread/scheduler.