混合Action和API调用时,Xamarin会崩溃(是否关注线程?) [英] Xamarin crashes when mixing Action and API calls (threading concern?)

查看:129
本文介绍了混合Action和API调用时,Xamarin会崩溃(是否关注线程?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到问题-出现断言崩溃"-在Xamarin中混合了Action和API调用.

I'm having issues - with an "Assertion crash" - mixing Action and API calls in Xamarin.

MainPage.xaml.cs

private void Button_clicked(...) {
  serialLoader.Load(targetID, OnLoadSuccessful):
}

private void OnLoadSuccessful(TargetResult result) {
  // Do something
}

SerialLoader.cs

public void Load(string targetID, Action<TargetResult> OnLoadSuccessful) {
  // API service call that "forces" me to use the following
  client.LoadCompleted += (sender, e) => OnSerialLoadCompleted(sender, e, targetID, OnLoadSuccessful);
  client.LoadAsync(...) // I don't think this call is "really async" as return type is void.
}

public void OnSerialLoadCompleted(object sender, LoadCompletedEventArgs e, string targetID, Action<TargetResult> OnLoadSuccessful) {
  if (...) { // If loaded successfully...
  // .. call the Action passing the result so that I can handle it in the MainPage.xaml.cs 
    OnLoadSuccessful(e.Result);
  }
}

这会使应用程序崩溃并出现以下错误

This crashes the application with the following errors

仿真器

03-28 19:12:01.169 W/        (22852): Thread 0xcddbacd0 may have been prematurely finalized
03-28 19:12:01.169 W/        (22852): Thread 0xcddbacd0 may have been prematurely finalized
03-28 19:12:01.169 F/        (22852): * Assertion at /Users/builder/jenkins/workspace/xamarin-android-d15-6/xamarin-android/external/mono/mono/utils/mono-threads.c:563, condition `info' not met

智能手机(API 21)

SMARTPHONE (API 21)

03-28 21:29:27.467 E/mono-rt (28909): =================================================================
03-28 21:29:27.467 E/mono-rt (28909): Got a SIGSEGV while executing native code. This usually indicates
03-28 21:29:27.467 E/mono-rt (28909): a fatal error in the mono runtime or one of the native libraries 
03-28 21:29:27.467 E/mono-rt (28909): used by your application.
03-28 21:29:27.467 E/mono-rt (28909): =================================================================
03-28 21:29:27.467 E/mono-rt (28909): 
03-28 21:29:27.467 F/libc    (28909): Fatal signal 11 (SIGSEGV), code 2, fault addr 0x9b691fd8 in tid 29095 (Threadpool work)

我认为这与在多个线程上执行有关;我尝试添加"Device.BeginInvokeOnMainThread"(无法正常工作),并尝试用Func替换我的Action,但没有运气.另外,我很惊讶模拟器和智能手机都崩溃了!

I assume this is related to executions on multiple threads; I've tried adding "Device.BeginInvokeOnMainThread" (didn't work) and tried to replace my Action by Func but with no luck. Also, I'm surprised both the emulator and the smartphone crash so badly!

感谢您的帮助.

其他详细信息: Windows 10上的VS2017社区15.6.4 Xamarin表格2.5.0.280555 目标Android SDK 8.1(API 27-Oreo)

Additional details: VS2017 Community 15.6.4 on Windows 10 Xamarin Forms 2.5.0.280555 Target Android SDK 8.1 (API 27 - Oreo)

推荐答案

好的,我很抱歉.上面的症状是正确的,该应用程序确实崩溃了,没有提供任何反馈.但是这种担忧似乎与我将PushingAsync插入到MainPage.xaml.cs中的OnLoadSuccessful方法中的目标页面有关.

OK, my apologies. The symptoms above were correct and the application did crash without providing any feedback. But the concern seems related to the target page I'm PushingAsync to into the OnLoadSuccessful method in MainPage.xaml.cs.

为什么会发生这种情况仍不清楚,但请忽略此问题.

Why this happens is still totally unclear but please disregard this question.

这篇关于混合Action和API调用时,Xamarin会崩溃(是否关注线程?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆