[英]Xamarin crashes when mixing Action and API calls (threading concern?)
我遇到問題-“斷言崩潰”-在Xamarin中混合了Action和API調用。
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);
}
}
這會使應用程序崩潰,並出現以下錯誤
仿真器
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)
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,但沒有運氣。 另外,我很驚訝模擬器和智能手機都崩潰了!
任何幫助表示贊賞。
其他詳細信息:Windows 10 Xamarin Forms 2.5.0.280555上的VS2017社區15.6.4目標Android SDK 8.1(API 27-Oreo)
好,我道歉。 上面的症狀是正確的,該應用程序確實崩潰了,沒有提供任何反饋。 但是問題似乎與我將PushingAsync插入到MainPage.xaml.cs中的OnLoadSuccessful方法中的目標頁面有關。
為什么發生這種情況仍然是完全不清楚的,但請忽略此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.