0

So I have been working on a issue with the idea of sorting the grid view on column header click. The sort works well and fast whilst the collection is small however when the collection grows to around 1 million items, the sorting can take quite a bit of time. As the sorting is performed on the UI thread the application locks out. I need to keep the application alive whilst this sorting is being performed. I have tried running this on a separate UI thread but to no avail and running this using an async call the the application dispatcher still with no joy. Please the code below illustrating the sort logic where sortBy is the bind path to sort by.

private void Sort(string sortBy, ListSortDirection direction, ListView myListView, CollectionView myCollectionView)
{
    using(myCollectionView.DeferRefresh())
    {
        myCollectionView.SortDescription.Clear();
        myCollectionView.SortDescription.Add(new SortDescription(sortBy, direction);
    }
    myListView.ScrollIntoView(myListView.SelectedItem);
}
Rolodium
  • 343
  • 1
  • 2
  • 12
  • 3
    Displaying a million entries in an app is highly irregular. 1. Are you sure paging won't fit your scenario better? 2. If you insist on doing it this way, you can use a thread-safe collection that will enable this type of work http://stackoverflow.com/questions/2137769/where-do-i-get-a-thread-safe-collectionview – Moti Azu Dec 04 '14 at 14:42
  • Hi, I think that this can solve your problem: http://stackoverflow.com/questions/19579734/add-element-by-element-to-listview-without-blocking-ui :) try it – Stefano Bafaro Dec 04 '14 at 14:44
  • It is an unusual situation, however by rights this collection shouldn't grow larger than 100 entries however, there are certain circumstances where it could grow to an incredibly large size. I will look into the thread-safe collection, thanks. – Rolodium Dec 04 '14 at 14:45
  • 1
    If it only grows large in an unusual situation then I would just activate a small warning - collection size as grown to X sort will be slow. – paparazzo Dec 04 '14 at 15:15
  • Blam, I have decided to go with your option, seems the simplest for something that in theory should never occur in my system but a short check for a large dataset, prompt for "are you sure you want to continue?" and change the cursor to wait seemed to be suitable for the task at hand. – Rolodium Dec 05 '14 at 10:37

0 Answers0