C# 域在解析ThreadSafeReference时崩溃

C# 域在解析ThreadSafeReference时崩溃,c#,android,asynchronous,realm,thread-safety,C#,Android,Asynchronous,Realm,Thread Safety,当试图从一个单独的线程返回结果时,我的应用程序只是停止工作并退出,我已经能够用可用的信息编写此代码 public async override Task<IQueryable<Entry>> FindAsync(string inputText) { var resultingEntries = await Task.Run(() => { // The heavy stuff starts here, in anew thread.

当试图从一个单独的线程返回结果时,我的应用程序只是停止工作并退出,我已经能够用可用的信息编写此代码

public async override Task<IQueryable<Entry>> FindAsync(string inputText)
{
    var resultingEntries = await Task.Run(() =>
    {
        // The heavy stuff starts here, in anew thread.
        using (var realm = Realm.GetInstance(DbConfig))
        {
            // All data
            var bgHaystack = realm.All<Entry>();

            // Because realm doesn't support some of the LINQ operations on not stored fields (Content)
            // the set of entries is converted to a IEnumerable.
            IEnumerable<Entry> subset = bgHaystack;

            // This is where the search gets actually done
            subset = subset.Where(entry => entry.Content.ToLower().StartsWith(inputText));

            // Extracts ids
            var foundEntryIds = ExtractIdsFromEntries(subset);

            // Select entries
            var foundEntries = FindingManyMatches(bgHaystack, foundEntryIds.ToArray());

            return ThreadSafeReference.Create(foundEntries);
        }
    });

    var results = Realm.GetInstance(DbConfig).ResolveReference(resultingEntries);
    return results;
}
公共异步覆盖任务FindAsync(字符串inputText)
{
var resultingEntries=等待任务。运行(()=>
{
//沉重的东西从这里开始,以新的方式。
使用(var realm=realm.GetInstance(DbConfig))
{
//所有数据
var bghastack=realm.All();
//因为realm不支持非存储字段(内容)上的某些LINQ操作
//条目集将转换为IEnumerable。
IEnumerable subset=bgHaystack;
//这就是实际完成搜索的地方
子集=子集。其中(entry=>entry.Content.ToLower().StartsWith(inputText));
//提取ID
var foundEntryId=ExtractIdsFromEntries(子集);
//选择条目
var foundEntries=FindingManyMatches(bghastack,foundEntryId.ToArray());
返回ThreadSafeReference.Create(foundEntries);
}
});
var results=Realm.GetInstance(DbConfig.ResolveReference)(resultingEntries);
返回结果;
}
一切都很好,除了第二行到最后一行,我想得到结果对象,你知道这里出了什么问题,以及如何解决这个问题吗

堆栈跟踪:

Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

No native Android stacktrace (see debuggerd output).

=================================================================
    Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x7cdcb67c70):0x7cdcb67c60  c0 03 5f d6 c8 02 80 52 e0 03 08 2a c0 03 5f d6  .._....R...*.._.
0x7cdcb67c70  08 00 40 79 09 3d 0e 53 08 3d 00 12 69 01 00 35  ..@y.=.S.=..i..5
0x7cdcb67c80  09 01 13 12 2a 01 00 32 0b fc 5f 48 7f 21 29 6b  ....*..2.._H.!)k
0x7cdcb67c90  a1 00 00 54 0a 7c 0b 48 8b ff ff 35 e0 03 1f 2a  ...T.|.H...5...*

================================================

05-08 23:09:47.037 D/Mono    (25933): Found as 'shared_realm_resolve_object_reference'.=================
    Managed Stacktrace:
=================================================================
      at <unknown> <0xffffffff>
      at NativeMethods:resolve_query_reference <0x00007>
      at Realms.SharedRealmHandle:ResolveReference <0x00243>
      at Realms.Realm:ResolveReference <0x0008f>
      at <FindAsync>d__9:MoveNext <0x0062f>
      at MoveNextRunner:InvokeMoveNext <0x000f3>
      at System.Threading.ExecutionContext:RunInternal <0x003af>
      at System.Threading.ExecutionContext:Run <0x0006b>
      at MoveNextRunner:Run <0x00193>
      at <>c:<.cctor>b__7_0 <0x0009b>
      at <>c__DisplayClass2_0:<Post>b__0 <0x00093>
      at RunnableImplementor:Run <0x000bb>
      at Java.Lang.IRunnableInvoker:n_Run <0x000c3>
      at Android.Runtime.DynamicMethodNameCounter:20 <0x000af>
      at Android.Runtime.DynamicMethodNameCounter:20 <0x000e3>
=================================================================

05-08 23:09:47.037 D/Mono    (25933): DllImport searching in: 'realm-wrappers' ('librealm-wrappers.so').
05-08 23:09:47.037 D/Mono    (25933): Searching for 'shared_realm_resolve_list_reference'.
05-08 23:09:47.037 D/Mono    (25933): Probing 'shared_realm_resolve_list_reference'.
05-08 23:09:47.037 D/Mono    (25933): Found as 'shared_realm_resolve_list_reference'.
05-08 23:09:47.037 D/Mono    (25933): DllImport searching in: 'realm-wrappers' ('librealm-wrappers.so').
05-08 23:09:47.037 D/Mono    (25933): Searching for 'shared_realm_resolve_query_reference'.
05-08 23:09:47.037 D/Mono    (25933): Probing 'shared_realm_resolve_query_reference'.
05-08 23:09:47.037 D/Mono    (25933): Found as 'shared_realm_resolve_query_reference'.
05-08 23:09:47.040 F/libc    (25933): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x188 in tid 25933 (panyname.dosham), pid 25933 (panyname.dosham)
05-08 23:09:47.061 D/Mono    (25933): DllImport searching in: 'realm-wrappers' ('librealm-wrappers.so').
05-08 23:09:47.062 D/Mono    (25933): Searching for 'query_destroy'.
05-08 23:09:47.062 D/Mono    (25933): Probing 'query_destroy'.
05-08 23:09:47.062 D/Mono    (25933): Found as 'query_destroy'.
05-08 23:09:47.259 I/panyname.dosha(25933): ProcessProfilingInfo new_methods=0 is saved saved_to_disk=0 resolve_classes_delay=8000
本机崩溃报告
=================================================================
在执行本机代码时收到SIGSEGV。这通常表明
mono运行时或某个本机库中出现致命错误
由您的应用程序使用。
=================================================================
没有本机Android stacktrace(请参阅debuggerd输出)。
=================================================================
基本故障地址报告
=================================================================
本机指令指针周围的内存(0x7cdcb67c70):0x7cdcb67c60 c0 03 5f d6 c8 02 80 52 e0 03 08 2a c0 03 5f d6。
0x7cdcb67c70 08 00 40 79 09 3d 0e 53 08 3d 00 12 69 01 00 35..@y..S..i..5
0x7cdcb67c80 09 01 13 12 2a 01 00 32 0b fc 5f 48 7f 21 29 6b…..*.2…..)K
0x7cdcb67c90 a1 00 00 54 0a 7c 0b 48 8b ff 35 e0 03 1f 2a…T.| H…5*
================================================
05-08 23:09:47.037 D/Mono(25933):被发现为“共享\领域\解析\对象\引用”=================
托管堆栈跟踪:
=================================================================
在
在NativeMethods:解析\查询\引用
在Realms.SharedRealmHandle:ResolveReference
领域:ResolveReference
在d___9:下一步
在MoveNextRunner:InvokeMoveNext
在System.Threading.ExecutionContext:RunInternal
在System.Threading.ExecutionContext:运行
在MoveNextRunner:运行
在c:b__7_0
在c___显示器上Class2_0:b__0
在RunnableImplementor:运行
在Java.Lang.irunableinvoker:n_运行
在Android.Runtime.DynamicMethodNameCounter:20
在Android.Runtime.DynamicMethodNameCounter:20
=================================================================
05-08 23:09:47.037 D/Mono(25933):DllImport在“realm wrappers”('librealm-wrappers.so')中搜索。
05-08 23:09:47.037 D/Mono(25933):搜索“共享领域\解析\列表\参考”。
05-08 23:09:47.037 D/Mono(25933):探测“共享的、领域的、解决的、列表的、参考的”。
05-08 23:09:47.037 D/Mono(25933):被发现为“共享的\域\解析\列表\引用”。
05-08 23:09:47.037 D/Mono(25933):DllImport在“realm wrappers”('librealm-wrappers.so')中搜索。
05-08 23:09:47.037 D/Mono(25933):搜索“共享领域、解析、查询、引用”。
05-08 23:09:47.037 D/Mono(25933):探测“共享领域、解析、查询、引用”。
05-08 23:09:47.037 D/Mono(25933):被发现为“共享\域\解析\查询\引用”。
05-08 23:09:47.040 F/libc(25933):致命信号11(SIGSEGV),代码1(SEGV_-MAPERR),tid 25933(panyname.dosham)中的故障地址0x188,pid 25933(panyname.dosham)
05-08 23:09:47.061 D/Mono(25933):DllImport在“realm wrappers”('librealm-wrappers.so')中搜索。
05-08 23:09:47.062 D/Mono(25933):搜索“查询/销毁”。
05-08 23:09:47.062 D/Mono(25933):探测“查询销毁”。
05-08 23:09:47.062 D/Mono(25933):发现为“查询销毁”。
05-08 23:09:47.259 I/panyname.dosha(25933):ProcessProfilingInfo新方法=0保存到\u磁盘=0解析\u类\u延迟=8000

看起来像是一个bug,删除了

using (var realm = Realm.GetInstance(DbConfig))
解决了这个问题,即

            var resultingEntries = await Task.Run(() =>
            {
                var allEntries = Realm.GetInstance(DbConfig).All<Entry>();

                // Because realm doesn't support some of the LINQ operations on not stored fields (Content)
                // the set of entries is converted to a IEnumerable.
                IEnumerable<Entry> subset = allEntries;

                // This is where the search gets actually done
                subset = subset.Where(entry => entry.Content.ToLower().StartsWith(inputText));

                // Extracts ids
                var foundEntryIds = ExtractIdsFromEntries(subset);

                // Select entries
                var foundEntries = FindingManyMatches(allEntries, foundEntryIds.ToArray());
                var foundEntriesCount = foundEntries.Count();

                return ThreadSafeReference.Create(foundEntries);
            });

            var results = Realm.GetInstance(DbConfig).ResolveReference(resultingEntries);
            return results;
var resultingEntries=等待任务。运行(()=>
{
var allEntries=Realm.GetInstance(DbConfig.All();
//因为realm不支持非存储字段(内容)上的某些LINQ操作
//条目集将转换为IEnumerable。
IEnumerable subset=allEntries;
//这就是实际完成搜索的地方
子集=子集。其中(entry=>entry.Content.ToLower().StartsWith(inputText));
//提取ID
var foundEntryId=ExtractIdsFromEntries(子集);
//选择条目
var foundEntries=FindingManyMatches(allEntries,foundEntryId.ToArray());
var foundEntriesCount=foundEntries.Count();
返回ThreadSafeReference.Create(foundEntries);
});
var results=Realm.GetInstance(DbConfig.ResolveReference)(resultingEntries);
返回结果;

看起来像是一个bug,删除了

using (var realm = Realm.GetInstance(DbConfig))
解决了这个问题,即

            var resultingEntries = await Task.Run(() =>
            {
                var allEntries = Realm.GetInstance(DbConfig).All<Entry>();

                // Because realm doesn't support some of the LINQ operations on not stored fields (Content)
                // the set of entries is converted to a IEnumerable.
                IEnumerable<Entry> subset = allEntries;

                // This is where the search gets actually done
                subset = subset.Where(entry => entry.Content.ToLower().StartsWith(inputText));

                // Extracts ids
                var foundEntryIds = ExtractIdsFromEntries(subset);

                // Select entries
                var foundEntries = FindingManyMatches(allEntries, foundEntryIds.ToArray());
                var foundEntriesCount = foundEntries.Count();

                return ThreadSafeReference.Create(foundEntries);
            });

            var results = Realm.GetInstance(DbConfig).ResolveReference(resultingEntries);
            return results;
var resultingEntries=等待任务。运行(()=>
{
var allEntries=Realm.GetInstance(DbConfig.All();
//因为领域不支持