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;
}