Xamarin 领域中的Realms.SynchronizationContextEventLoop错误
当我们尝试多次更新领域数据库时,会抛出以下错误Xamarin 领域中的Realms.SynchronizationContextEventLoop错误,xamarin,realm,Xamarin,Realm,当我们尝试多次更新领域数据库时,会抛出以下错误 NHANDLED EXCEPTION: System.ObjectDisposedException: Safe handle has been closed at (wrapper managed-to-native) System.Object:wrapper_native_0xda0c96a0 (intptr) at Realms.SynchronizationContextEventLoopSignal+EventLoop+<Post
NHANDLED EXCEPTION:
System.ObjectDisposedException: Safe handle has been closed
at (wrapper managed-to-native) System.Object:wrapper_native_0xda0c96a0 (intptr)
at Realms.SynchronizationContextEventLoopSignal+EventLoop+<Post>c__AnonStorey0.<>m__0 (System.Object _) [0x00012] in <550621f4184f47c0bdfce087c391c293>:0
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <d855bac285f44dda8a0d8510b679b1e2>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <d855bac285f44dda8a0d8510b679b1e2>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <d855bac285f44dda8a0d8510b679b1e2>:0
at (wrapper dynamic-method) System.Object:f9edc18f-c720-423d-8576-23c20d8f6a89 (intptr,intptr)
你能试试
wait
-ingWriteAsync
调用或使用同步版本吗?@NikolaIrinchev这不起作用,我也试过了,每次都会崩溃。我建议提交一个问题,因为我们需要更多信息来进一步调查,而堆栈溢出通常不适合这样做。
private void updateGetData(EventType e)
{
try
{
Realm realm = Realm.GetInstance();
realm.WriteAsync(tempRealm =>
{
if (Settings.IsSingleOpportunityUpdated == false)
{
tempRealm.Add(e.response, true);
}
else if (Settings.IsSingleOpportunityUpdated)
{
if (e.response != null && e.response.opportunitiesList.Count > 0)
{
long opportunityId = e.response.opportunitiesList[0].opportunityId;
var opportunity = tempRealm.All<Opportunity>().FirstOrDefault(d => d.opportunityId == opportunityId);
e.response.opportunitiesList[0].isOpportunitySync = 0;
e.response.opportunitiesList[0].isSync = SyncStatus.SYNCED;
e.response.opportunitiesList[0].mOpportunityId = opportunity.mOpportunityId;
Debug.WriteLine("Opportunity Id after getOpportunity " + opportunity.opportunityId + " " + opportunityId + " " + e.response.opportunitiesList[0].isSync);
tempRealm.Add(e.response.opportunitiesList[0], true);
}
else
{
Debug.WriteLine("RealmDB opportunity response is empty " + Settings.IsSingleOpportunityUpdated);
}
}
});
}
catch(Exception exception)
{
Debug.WriteLine("RealmDB " + exception.StackTrace);
}
}