-3

I am trying to load a 10k row database XML export into combo box in C# but the time to open the window takes forever and I am sure 10k rows isnt that much to process, yet it still takes me about 20 seconds to finish maxing out one of my CPU threads. I tried creating a new thread in C# but got a cross-thread error. Any way for me to improve the loading time into 1 or 2 seconds?

public partial class AddGameWindow : Form
{
    public AddGameWindow()
    {
        InitializeComponent();
        Application.UseWaitCursor = true;
    }

    private void AddGameWindow_Load(object sender, EventArgs e)
    {
        var doc = XDocument.Parse(Properties.Resources.GameDB);
        var rows = doc.Descendants("table").Select(el => new Game
        {
            Name = el.Element("title").Value,
            Url = el.Element("link").Value,
            Img = el.Element("imglink").Value
        });

        if (gamesList.Items.Count == 0 ) {
            // for some reason fires again when window closed :(
            int i = 0;
            foreach (var row in rows)
            {
                //nejak to tam nahazet at to dlouho netrva
                gamesList.Items.Insert(i, row.Name);
                i++;
            }
            Application.UseWaitCursor = false;
        }
    }
}
class Game
{
    public string Name;
    public string Url;
    public string Img;
}
Martin Joneš
  • 97
  • 2
  • 13
  • no, put 10K rows in dropdown list is just not right. – urlreader Dec 29 '20 at 17:42
  • 2
    Ten thousand rows in a dropdown is just not good UI. Figure out a way to make the list smaller, perhaps by using a category dropdown first. – Robert Harvey Dec 29 '20 at 17:43
  • It is for a school project, im not gonna spend all day doing a list filter, moreover my deadline is in a few days, haha :D – Martin Joneš Dec 29 '20 at 17:44
  • 2
    *I am trying to load a 10k row ... into combo box in C#* - you appear to have posted on the wrong site. Please go immediately to ux.stackexchange.com and tell them of your plans. Wear something of limited combustibility – Caius Jard Dec 29 '20 at 17:44
  • 1
    Or perhaps [this](https://stackoverflow.com/q/11780558/102937). – Robert Harvey Dec 29 '20 at 17:45
  • 2
    Loading 10k rows in a Combo-Box is not a great idea. I mean like, at all. You can load, for example, 100 rows, then if user scrolls down, load 100 more and so on. Also, you can use asynchronous methods to load data which won't block your UI. – Dorin Baba Dec 29 '20 at 17:46
  • 2
    No human user can understand or be able to find anything within a massive, continuous, unfiltered list of 10,000 options. That's ridiculous. The reason the combobox doesn't work well with it is because it's not optimised for that quantity of data, because the designers of it assumed that no-one would be daft enough to put more than a few dozen items in it, at most. If you have a few days until your deadline you have plenty of time to figure out how to do a filter or an autocomplete search, and make a UI that is sane and actually usable. – ADyson Dec 29 '20 at 17:49

1 Answers1

1

You'll need to leverage BeginUpdate/EndUpdate if you're pushing a huge number of items into a list based control one at a time

Do heed the advice in the comments though; a combo of more than about 20 items is pretty unusable. Look at a "type in this textbox and use it as a filter", possibly with "only start filtering after the user typed 3 characters" and a "only start filtering after a delay of 500ms rather than filtering upon every keypress" type behavior..

Caius Jard
  • 72,509
  • 5
  • 49
  • 80