17
5
内容纲要
在实际开发过程中,我们需要使用多线程来保证UI不被卡住,mono for android提供了非常方便的方法来进行多线程开发,其中一种就是使用Thread,下面是一个例子:
var progressDialog = ProgressDialog.Show(this, null, "加载中...", true); ;
//启动页面
new Thread(new ThreadStart(delegate
{
loginuser = userapi.Login(Et_phone.Text, Et_pwd.Text, true);
this.RunOnUiThread(() =>
{
progressDialog.Hide();
if (loginuser.uid != null && loginuser.uid.Length != 0)
{
Finish();
}
else
{
Toast.MakeText(this, "登录失败,请输入正确的用户名或密码", ToastLength.Short).Show();
}
});
})).Start();
这里其实是使用了C#的线程Thread来完成,不过有一个确定,就是不能终止当前的线程,比如如果这个线程执行慢,我先终止,暂时没有找到终止的办法