Im使用Xamarin和C#构建一个android应用程序。 该应用程序使用restsharp连接到我的服务器并提取我需要的信息。Xamarin - 使用async/await和ProgressDialog
我试图建立一个注册页面,我想检查用户是否存在。 我想在后台执行此操作,而用户看到ProgressDialog。
这是我的代码:
if (!string.IsNullOrEmpty(PhoneNumber) && !string.IsNullOrEmpty(Password)
&& !string.IsNullOrEmpty(LicenceId) && LicenceImage.Length > 1)
{
ProgressDialog mDialog = new ProgressDialog(this);
mDialog.SetMessage("Loading data...");
mDialog.SetCancelable(false);
mDialog.Show();
bool checkExistance = await api.CheckIfExist(PhoneNumber);
if (checkExistance)
{
Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this);
alert.SetTitle("");
}
else
{
Intent intent = new Intent(this, typeof(RegisterDone));
StartActivity(intent);
}
}
的ProgressDialog节目,但总比没有happedns。 我试图用其他方式做到这一点,但仍然在不断努力。
这是干什么用的吗? Thx
提防异步的,因为它创造了一个新的线程,并改变你需要在UI线程的对话框。 – rmjoia
您是否尝试过使用断点来查看'api.CheckIfExist(PhoneNumber);'是否运行? –
是的,thia方法运行并返回一个布尔值。问题是服务器返回结果后什么也没有发生 –