gpt4 book ai didi

c# - 奇怪的句柄必须是对话框中的有效异常

转载 作者:行者123 更新时间:2023-12-05 00:04:56 24 4
gpt4 key购买 nike

我收到报告说我在我的应用程序中行为不端。我显示一个同步成功对话框,让用户知道他们的数据已经同步。一些用户表示他们没有看到同步成功的对话框,进度条只停留在 100%/100%,他们需要按返回退出。

问题不容易重现,事实上,我无法真正做到这一点,但我们创建的日志显示了出现问题的区域。

using System;
using System.Collections.Generic;
using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using Classes;
using Microsoft.AppCenter.Crashes;
using Services;
using System.Threading;
using Helpers;

namespace Dialogs
{
public class ProgressBarDialog : DialogFragment
{
private ProgressBar progressBar;
private OnProgressFinished onProgressFinished;
int _countSeconds;
object _lock = new object();
private TextView progressText;
private LinearLayout titleBackground;
private Button yes, no;
private static string title, description;
private OnItemClick callback;

public interface OnItemClick
{
void OnItemClick(int id);
}

public interface OnProgressFinished
{
void OnProgressFinished(int id);
}

public static ProgressBarDialog NewInstance(Bundle bundle, string passedTitle, string passedDesc)
{
var fragment = new ProgressBarDialog();
title = passedTitle;
description = passedDesc;
return fragment;
}

public override void OnAttach(Android.Content.Context context)
{
base.OnAttach(context);
try
{
callback = (OnItemClick)context;
}
catch (Exception e)
{
Crashes.TrackError(e);
}

try
{
onProgressFinished = (OnProgressFinished)context;
}
catch (Exception e)
{
Crashes.TrackError(e);
}
}

public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
//return customview for the fragment
View view = inflater.Inflate(Resource.Layout.ProgressDialog, container, false);
progressBar = view.FindViewById<ProgressBar>(Resource.Id.progressBar1);
progressText = view.FindViewById<TextView>(Resource.Id.progressText);
progressBar.Max = 100;
SampleDatabase db = new SampleDatabase();
SampleRESTFulService save = new SampleRESTFulService(Activity);
List<Sample> samples = db.Get();
int sampleCount = samples.Count;

if (sampleCount > 0)
{
Activity.RunOnUiThread(async () =>
{
using (var cancellationTokenSource = new CancellationTokenSource())
{
cancellationTokenSource.CancelAfter(TimeSpan.FromMinutes(5));

try
{
int successfullySynced = 0;
foreach (Sample sample in samples.ToArray())
{
cancellationTokenSource.Token.ThrowIfCancellationRequested();
if (sample.Tag.Equals("NR"))
{
db.Delete(sample);
}

bool isSuccess = await save.SaveAsync(sample, cancellationTokenSource.Token);
if (isSuccess)
{
++successfullySynced;
db.Delete(sample);
samples.Remove(sample);
progressBar.Progress = successfullySynced * 100 / sampleCount;
progressText.Text = progressBar.Progress.ToString() + "%";
}
else if (isSuccess == false && cancellationTokenSource.IsCancellationRequested)
{
onProgressFinished.OnProgressFinished(1);
Dismiss();
}

CheckProgress(progressBar.Progress);
}
}
catch (Exception ex)
{
LoggerHelper.LogUser("ProgressBarDialog OnCreateView Error", ex.ToString());

Console.WriteLine(ex);
}

if (cancellationTokenSource.IsCancellationRequested)
{
Dismiss();
onProgressFinished.OnProgressFinished(1);
}
else if (progressBar != null && progressBar.Progress < 100)
{
Dismiss();
onProgressFinished.OnProgressFinished(1);
}
}
});
}
return view;
}

// This is the function where the exception is kicking off.
public void CheckProgress(int progress)
{
try
{
lock (_lock)
{
if (progress >= 100)
{
Dismiss();
onProgressFinished.OnProgressFinished(0);
}
}
}
catch (Exception ex)
{
LoggerHelper.LogUser("ProgressBarDialog CheckProgress Error", ex.ToString());
}

}
}
}

我遇到的异常是:

4/10/2020 1:15:58 PM] - System.ArgumentException: Handle must be valid. Parameter name: instance at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00009] in <8cb56b2f65354c9f9fbb25da78a6cf09>:0 at Android.Runtime.JNIEnv.CallObjectMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in :0 at Android.Content.ISharedPreferencesEditorInvoker.PutString (System.String key, System.String value) [0x0006c] in :0 at Activities.SampleListActivity.OnProgressFinished (System.Int32 id) [0x00154] in :0 at Dialogs.ProgressBarDialog.CheckProgress (System.Int32 progress) [0x00022] in :0

我的回调函数是这样的:

public void OnProgressFinished(int id)
{
if (id == 1)
{
if (!IsFinishing && informDialog != null && IsForeground)
{
editor.PutString("Name", "");
editor.Commit();
updateAdapter();
informDialog.Dismiss();

SampleDatabase sDb = new SampleDatabase();
if(sDb.Get().ToArray().Count() > 0)
{
TrySyncAgain();
}
else
{
if (!IsFinishing && informDialog != null && IsForeground)
{
editor.PutString("PASSEDHERD", "");
editor.Commit();
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.SetTitle("Sync Successful");
alert.SetMessage("You're samples have been synced successfully.");
alert.SetPositiveButton("Yes", (senderAlert, args) =>
{
LoggerHelper.LogUser(passedHerd.Tech_ID, string.Format("{0} clicked OK on sync successful.", passedHerd.Tech_ID));
LoggerHelper.Log(passedHerd.Herd_Test_ID, String.Format("User: {0}, pressed Yes on sync successful", passedHerd.Tech_ID));
End(true);
});
Dialog dialog = alert.Create();
dialog.Show();
}
}

}
}
else if (id == 0)
{
if (!IsFinishing && informDialog != null && IsForeground)
{
editor.PutString("PASSEDHERD", "");
editor.Commit();
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.SetTitle("Sync Successful");
alert.SetMessage("You're samples have been synced successfully.");
alert.SetPositiveButton("Yes", (senderAlert, args) =>
{
LoggerHelper.LogUser(passedHerd.Tech_ID, string.Format("{0} clicked OK on sync successful.", passedHerd.Tech_ID));
LoggerHelper.Log(passedHerd.Herd_Test_ID, String.Format("User: {0}, pressed Yes on sync successful", passedHerd.Tech_ID));
End(true);
});
Dialog dialog = alert.Create();
dialog.Show();
}
}
}

我尝试将 Null 传递给回调,但由于需要 Int 值,它不会接受它。

如有任何帮助,我们将不胜感激。谢谢

最佳答案

尝试使用 Firebase TeSTLab 并安装 Crashlytics。这将帮助您实时查看用户应用程序何时崩溃。这对我帮助很大

关于c# - 奇怪的句柄必须是对话框中的有效异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61225706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com