码迷,mamicode.com
首页 > 编程语言 > 详细

Mono 异步加载数据更新主线程

时间:2014-07-15 09:36:32      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   数据   art   

主要是用 async await 调用 RunOnUiThread来更新。

调用函数:

 

//异步加载数据开始
doInBackground ();
//异步加载数据开始end
protected async void doInBackground ()
{
       var result = await Task.Factory.StartNew((Func<string>)onSuccessfulLogin);

                if (result=="") {

                    await Task.Factory.StartNew (() => {
                        RunOnUiThread (delegate() {
                            //跳转到主页面
                            Intent intent = new Intent();
                            intent.SetClass(this, typeof(Main));
                            StartActivity(intent);
                            Finish ();
                        });
                    });
                }
}
    protected string  onSuccessfulLogin ()
        {


            try {
                Thread.Sleep (2000);
                Hashtable pars = new Hashtable();
                pars.Add("UserName",mAccount);
                pars.Add("Password", mPassword);
                UserInfoDao userinfodao = new UserInfoDao ();
                userinfomodel = userinfodao.getWebservice (pars);

                //判断登录

                if (userinfomodel != null) {
                    if (userinfomodel.UserID > 0) {

                        //保持登录的状态 bgein
                        ISharedPreferences shared = GetSharedPreferences("UserInfo", FileCreationMode.Private);
                        string value = shared.GetString("UserInfo", "");
                        value =userinfomodel.UserID.ToString().Trim()+"|"+userinfomodel.UserName+"|"+userinfomodel.Token ;
                        ISharedPreferencesEditor editor = shared.Edit();
                        editor.PutString("UserInfo",value);
                        editor.Commit();
                        //保持登录的状态 end

                    }
                }
                else
                {
                    return "用户名或密码错误!";
                }
            } catch (Exception e) {
                return e.ToString();
            }

            return "";

        }

 

 

 

Mono 异步加载数据更新主线程,布布扣,bubuko.com

Mono 异步加载数据更新主线程

标签:style   blog   color   os   数据   art   

原文地址:http://www.cnblogs.com/phinex/p/3843973.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!