【发布时间】:2021-03-01 17:01:32
【问题描述】:
基于this 答案,我发现我无法从另一个线程访问领域对象,但从答案中,我了解到我可以存储领域对象的引用,然后在另一个线程中使用它。
我想循环它直到它被插入,但问题是我无法访问另一个线程上的var document 和var s。
那么我该如何找到解决该问题的方法呢?
private async void UpdateNotifications_OnAdd(object sender, EventArgs e)
{
//UpdateNotification is my RealmObject
var s = (UpdateNotifications)sender;
//Here I want to find the document that has the id from my updateNotification
var document = realm.Find<Document>(s.Identifier)
await Task.Run(async () =>
{
while(!s.Inserted)
{
//Here I want to access my document and my S
string text = queryFinder(document)
realm.Write(() =>
{
s.Inserted = true;
});
}
}
}
【问题讨论】: