xamarin.forms或者android 在其他线程更新UI

2019-05-08  本文已影响0人  毛毛v5

如果是xmarin.forms,使用:

                try
                {

                    Xamarin.Forms.Device.BeginInvokeOnMainThread(() => {
                        MessagingCenter.Send(App.Current, "log", e1.Message +"\r\n"+ e1.Source); // 这里更新UI。
                    });
                }
                catch (Exception e2)
                {
                    Console.WriteLine(e2.Message);
                }

如果是android.

FusionField.currentActivity.runOnUiThread(new Runnable()    
        {    
            public void run()    
            {    
                Toast.makeText(getApplicationContext(), , "Update My UI",    
                        Toast.LENGTH_LONG).show();    
            }    
    
        });
上一篇下一篇

猜你喜欢

热点阅读