Reputation: 461
I have a user control that has a listview with gridview. I am using background worker to start loading animation, get the data and stop loading animation. All is good but the problem is after I get data and bind it to grid, it takes long time to render grid and loading animation freezes in that time.
BackgroundWorker bw = new BackgroundWorker() { WorkerReportsProgress = true };
public FormUserControl()
{
InitializeComponent();
presenter = new FormPresenter(this);
bw.DoWork += new DoWorkEventHandler(LoadInfo);
bw.RunWorkerCompleted += LoadInfo_RunWorkerCompleted;
Dispatcher.Invoke(new Action(() =>
{
EnableLoading(true);
}), DispatcherPriority.ContextIdle);
bw.RunWorkerAsync();
}
void LoadInfo(object sender, DoWorkEventArgs e)
{
presenter.LoadFormInformation();
}
private void LoadInfo_RunWorkerCompleted(object sender,RunWorkerCompletedEventArgs e)
{
Dispatcher.Invoke(new Action(() =>
{
//here animation freezes
this.AjmStoreLog = this.GridInfo;
EnableLoading(false);
}), DispatcherPriority.ContextIdle);
}
I need to call EnableLoading(false); this function when grid rendering complete not at the LoadInfo_RunWorkerCompleted event.
Thanks for all help.
Upvotes: 0
Views: 346
Reputation: 5549
There are many cases where performance suffers simply because there's too much work to do, and a lot of that work has to happen on the UI thread. There's no magic bullet solution that can help there - if you have many items in your data source or if your templates are very complex...
I'd suggest looking at UI virtualization first, assuming there are many items and that's the main reason for performance problems. Without UI virtualization, list controls need to render every item in the data source, but enabling it will make it so that only the visible items need to be actually rendered on screen, which makes a massive difference.
Upvotes: 1