简体   繁体   English

Xamarin.ios UI 冻结

[英]Xamarin.ios UI freezing

I have a Xamarin.ios application which uses MySql.我有一个使用 MySql 的 Xamarin.ios 应用程序。 I want to show a IUActivityIndicatorView while program is trying to get data from MySql database.我想在程序尝试从 MySql 数据库获取数据时显示 IUActivityIndicatorView。

I tried the code below and the activity indicator appeared after data load which means the UI is freezing.我尝试了下面的代码,并且在数据加载后出现了活动指示器,这意味着 UI 正在冻结。 I searched about background workers in Xamarin.ios but I enden up with nothing.我在 Xamarin.ios 中搜索了有关后台工作人员的信息,但最终一无所获。

The code that I have tried:我尝试过的代码:

Task.Run(indicator.StartAnimating);

I tried it without Task.Run as well but the result is the same.我也在没有 Task.Run 的情况下尝试过,但结果是一样的。

Instead of making the indicator.StartAnimating code line work on another thread, I changed the MySql method's thread by the following code:我没有让 indicator.StartAnimating 代码行在另一个线程上工作,而是通过以下代码更改了 MySql 方法的线程:

new System.Threading.Thread(new System.Threading.ThreadStart(() => {
    InvokeOnMainThread(() => {
      MySqlMethod();
    });
})).Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM