I’m using ListView in VirtualMode to show extremely big number of rows, millions of rows.
The data of the rows stored in a Generic List.
Now i want implement a sort feature, that will sort the List by some Comparer.
The problem is that for now, an average single sort takes around 30 seconds, and during this time the user cannot do anything with the ListView and have to wait until it ends.
Not every user will accept to wait that much time, most of users would cancel the sort, if they could, and i want to allow that cancel feature. Unfortunately, the built-in List.Sort cannot be cancelled nor Array.Sort.
For now the sort occurring on separate thread, so I could use Thread.Abort, but it probebly will result in corrupted List, unacceptable for me.
Is there something i can do except reimplement the whole Sort algorithm by myself?
thanks.
Copy the list, sort the copy in a thread then replace the original list (if the sort completes without getting interrupted).
But I’d go with Martinho’s suggestion if possible – having the millions of rows in the application to begin with feels wrong to me. Databases can do a far better job of filtering and sorting data before it gets to you.