List<T>
has more than 300 elementsListview
binding thisList<T>
when page show, but delay is more than 10s
Code:
List<app_process> saveList = new List<app_process>();
public ProcessPage() {
InitializeComponent();
saveList = getProcessDatas();
this.processList.ItemsSource = saveList;
}
I try to use Thread and dialog to optimize this problem but it is a failure.
List<app_process> saveList = new List<app_process>();
public ProcessPage(){
InitializeComponent();
UserDialogs.Instance.ShowLoading("Loading");
new Thread(new ThreadStart(() =>
{
saveList = getProcessDatas();
this.processList.ItemsSource = saveList;
Device.BeginInvokeOnMainThread(() =>
{
UserDialogs.Instance.HideLoading();
});
})).Start();
}
What's wrong with it? How can I solve it?
CodePudding user response:
Try overriding OnAppearing method and then run your processor async.
protected override async void OnAppearing()
{
UserDialogs.Instance.ShowLoading("Loading");
var data = await Task.Run(() => getProcessDatas());
Device.BeginInvokeOnMainThread(() =>
{
this.processList.ItemsSource = data;
UserDialogs.Instance.HideLoading();
});
}