System.Threading.QueueUserWorkItemCallback 相关的启动崩溃

System.Threading.QueueUserWorkItemCallback related startup crash

在我的应用程序中,运行 在 LG G3 D855 上,我在启动时遇到此错误,通常在我的应用程序有一段时间未启动时发生,总是在它崩溃后重新启动它很好:

E/linker  ( 2105): readlink('/proc/self/fd/28') failed: Permission denied [fd=28]
E/linker  ( 2105): warning: unable to get realpath for the library "/vendor/lib/egl/eglsubAndroid.so". Will use given name.
E/mono    ( 2105): 
E/mono    ( 2105): Unhandled Exception:
E/mono    ( 2105): System.NullReferenceException: Object reference not set to an instance of an object
E/mono    ( 2105):   at Dictionary.Fragments.SearchFragment+<>c__DisplayClass13_0.<PerformSearch>b__0 (System.Object x) [0x00050] in <88db5ed5788f4131a4894bb5620511e9>:0 
E/mono    ( 2105):   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x0000e] in <8552b98493c447d5a7a1f07bdaff39bb>:0 
E/mono    ( 2105):   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x0008d] in <8552b98493c447d5a7a1f07bdaff39bb>:0 
E/mono    ( 2105):   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <8552b98493c447d5a7a1f07bdaff39bb>:0 
E/mono    ( 2105):   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x0002a] in <8552b98493c447d5a7a1f07bdaff39bb>:0 
E/mono    ( 2105):   at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in <8552b98493c447d5a7a1f07bdaff39bb>:0 
E/mono    ( 2105):   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <8552b98493c447d5a7a1f07bdaff39bb>:0

这是失败的代码:

private void PerformSearch(string input) {
  ThreadPool.QueueUserWorkItem( x => {
    if ( _tranService == null )
      _tranService = new TranslationService();

    var translations = _tranService.Translate( input );
    _transAdapter.Update( translations );
    Activity.RunOnUiThread( () => _transAdapter.NotifyDataSetChanged() );
  } );
}

请告诉我这是什么,这让我很烦。它也发生在我正在制作的另一个应用程序中,该应用程序使用相同类型的 ThreadPool.QueueUserWorkItem() 块。

我的安装:

Microsoft Visual Studio Professional 2015 Version 14.0.25431.01 Update 3 Microsoft .NET Framework Version 4.6.01586

Installed Version: Professional

Microsoft Visual Studio Tools for Applications 2015
00322-40000-00000-AA309 Microsoft Visual Studio Tools for Applications 2015

Visual Basic 2015 00322-40000-00000-AA309 Microsoft Visual Basic 2015

Visual C# 2015 00322-40000-00000-AA309 Microsoft Visual C# 2015

Visual C++ 2015 00322-40000-00000-AA309 Microsoft Visual C++ 2015

Application Insights Tools for Visual Studio Package 7.17.00119.9 Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1 14.1.21111.0 ASP.NET and Web Tools 2015.1

ASP.NET Web Frameworks and Tools 2012.2 4.1.41102.0 For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013 5.2.40314.0 For additional information, visit http://www.asp.net/

Azure App Service Tools v2.8.1 14.0.11123.0 Azure App Service Tools v2.8.1

Command Bus, Event Stream and Async Manager Merq Provides ICommandBus, IEventStream and IAsyncManager MEF services for loosely coupled Visual Studio extension components communication and integration.

Common Azure Tools 1.8 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Indent Guides 15 Indent Guides

Adds visual guides at each indentation level.

JavaScript Language Service 2.0 JavaScript Language Service

JavaScript Project System 2.0 JavaScript Project System

JetBrains ReSharper Ultimate 2016.2.2 Build 106.0.20160913.91321 JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2017 JetBrains, Inc.

Microsoft .NET Core Tools (Preview 2) 14.1.21111.0 Microsoft .NET Core Tools (Preview 2)

Microsoft Azure Mobile Services Tools 1.4 Microsoft Azure Mobile Services Tools

NuGet Package Manager 3.5.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer 1.2 Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Analysis Services 13.0.1605.88 Microsoft SQL Server Analysis Services Designer Version 13.0.1605.88

SQL Server Data Tools 14.0.60629.0 Microsoft SQL Server Data Tools

SQL Server Integration Services Microsoft SQL Server Integration Services Designer Version 13.0.1601.5

SQL Server Reporting Services 13.0.1605.88 Microsoft SQL Server Reporting Services Designers Version 13.0.1605.88

TypeScript 1.8.36.0 TypeScript tools for Visual Studio

Visual Studio Tools for Unity 2.8.0.0 Visual Studio Tools for Unity

Windows Installer XML Toolset 3.10.2.2516 Windows Installer XML Toolset version 3.10.2.2516 Copyright (c) Outercurve Foundation. All rights reserved.

Xamarin 4.2.2.11 (00fa5cc) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android 7.0.2.42 (501e63c) Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS 10.3.1.8 (7beaef4) Visual Studio extension to enable development for Xamarin.iOS.

通过不使用 ThreadPool.QueueUserWorkItem 而是使用 TPL,Task.Factory.StartNew() 来做同样的事情,我的两个应用程序都解决了这个问题。我没有找到 ThreadPool.QueueUserWorkItem 失败的原因,并且 Xamarin 没有记录对我的错误报告的响应。