It is my first time here and I am struggling to solve this issue. I have this piece of code:
try
{
progressBar1.Maximum = lista.Items.Count;
lista.BeginUpdate();
for (int i = 0; lista.Items.Count > i; i++)
//for (int i = lista.Items.Count - 1; -1 < i; i--)
{
if (lista.Items[i].SubItems[1].Text.ToLower().Contains(Text) == false)
{
lista.Items[i].Remove();
}
progressBar1.Value = progressBar1.Value + 1;
}
lista.EndUpdate();
progressBar1.Value = 0;
}
catch (Exception errore)
{
txt_info.Text = "" + errore.Message;
progressBar1.Value = 0;
}
The method lista.items[i].remove
is extremely slow.
lista
is a ListView
and I am working on a log file bigger than 50,000 lines.
Is there anyway to speed up the process?
lista.Items.RemoveAt(i)
differ in speed? Perhaps (counter-intuitively) the class has to go back and resolve the index itself. – Apothegmforeach
... I believe it reasonably ok to usefor
to remove items (eventually some piece of code have to do it anyway) - also obviously incorrectly written (like in sample above due to skipping items next to one that just removed) is bad idea. – Circus