I have a ListView which I populate with a lot of items, over 3000. This can take up to 15 seconds. Every time I add an item I want to update a label stating how many items have been added so far. To do so I use this code:
foreach (FileInfo f in dir.GetFiles("*.*", SearchOption.AllDirectories))
{
DateTime dt = GetDateTakenFromImage(Path.Combine(f.Directory.ToString(), f.Name));
count++;
labelLoadedLeft.Text = "Loading " + count + " files so far";
ListViewItem lSingleItem = lv.Items.Add(f.Name);
lSingleItem.SubItems.Add(dt.ToString("dd MMMM yyyy"));
lSingleItem.Tag = Path.Combine(f.Directory.ToString(), f.Name);
}
Unfortunately the label does not show until all items have been loaded.
I understand this has to do with the fact that I am doing a lengthy operation on thr UI thread and that I should probably be using a backgroundworker to do the work.
Does anyone know of good and simple examples on how to use background worker. What I have found so far is too complicated for me or too convoluted.
Thank you
Crouz
BeginUpdate\EndUpdatemethods on a list view, or just inserting all items at once usingAddRange.