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

时间:2017-01-27 12:23:01

标签: multithreading xamarin xamarin.android threadpool

在我的应用程序中,在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版本14.0.25431.01更新   3 Microsoft .NET Framework版本4.6.01586

     

已安装版本:专业

     

Microsoft Visual Studio Tools for Applications 2015
  00322-40000-00000-AA309用于应用程序的Microsoft Visual Studio工具   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

     

Visual Studio包7.17.00119.9的应用程序洞察工具   Visual Studio的应用程序洞察工具

     

ASP.NET和Web Tools 2015.1 14.1.21111.0 ASP.NET和Web工具   2015.1

     

ASP.NET Web框架和工具2012.2 4.1.41102.0另外   信息,请访问http://go.microsoft.com/fwlink/?LinkID=309563

     

ASP.NET Web框架和工具2013 5.2.40314.0有关其他信息   信息,请访问http://www.asp.net/

     

Azure App Service Tools v2.8.1 14.0.11123.0 Azure App服务工具   v2.8.1

     

Merq提供的命令总线,事件流和异步管理器   ICommandBus,IEventStream和IAsyncManager MEF服务松散   耦合Visual Studio扩展组件的通信和   集成。

     

通用Azure工具1.8提供Azure使用的公共服务   移动服务和Microsoft Azure工具。

     

缩进指南15缩进指南

     

在每个缩进级别添加可视指南。

     

JavaScript语言服务2.0 JavaScript语言服务

     

JavaScript Project System 2.0 JavaScript项目系统

     

JetBrains ReSharper Ultimate 2016.2.2 Build 106.0.20160913.91321   适用于Microsoft Visual Studio的JetBrains ReSharper Ultimate软件包。对于   有关ReSharper Ultimate的更多信息,请访问   http://www.jetbrains.com/resharper。版权所有©2017 JetBrains,Inc。

     

Microsoft .NET核心工具(预览2)14.1.21111.0 Microsoft .NET   核心工具(预览2)

     

Microsoft Azure移动服务工具1.4 Microsoft Azure Mobile   服务工具

     

NuGet Package Manager 3.5.0 Visual Studio中的NuGet包管理器。   有关NuGet的更多信息,请访问http://docs.nuget.org/

     

PreEmptive Analytics Visualizer 1.2 Microsoft Visual Studio   扩展以可视化PreEmptive中的汇总摘要   分析产品。

     

SQL Server Analysis Services 13.0.1605.88 Microsoft SQL Server   Analysis Services Designer版本13.0.1605.88

     

SQL Server数据工具14.0.60629.0 Microsoft SQL Server数据工具

     

SQL Server Integration Services Microsoft SQL Server集成   Services Designer版本13.0.1601.5

     

SQL Server Reporting Services 13.0.1605.88 Microsoft SQL Server   Reporting Services Designers版本13.0.1605.88

     

TypeScript 1.8.36.0 Visual Studio的TypeScript工具

     

用于Unity的Visual Studio工具2.8.0.0用于Unity的Visual Studio工具

     

Windows Installer XML工具集3.10.2.2516 Windows Installer XML   工具集版本3.10.2.2516版权所有(c)Outercurve Foundation。所有   保留权利。

     

Xamarin 4.2.2.11(00fa5cc)启用Visual Studio扩展   开发Xamarin.iOS和Xamarin.Android。

     

Xamarin.Android 7.0.2.42(501e63c)启用Visual Studio扩展   开发Xamarin.Android。

     

Xamarin.iOS 10.3.1.8(7beaef4)启用Visual Studio扩展   Xamarin.iOS的开发。

1 个答案:

答案 0 :(得分:0)

我的应用中已经修复了这个问题,不使用ThreadPool.QueueUserWorkItem而是使用TPL,Task.Factory.StartNew()执行相同的操作。我没有找到ThreadPool.QueueUserWorkItem失败的原因,而Xamarin没有记录对我的错误报告的回复。