I'm loading a bunch of files into a ListView
, and I use Image.FromFile()
and .Width
and .Height
to display the the resolution of each file in a designated column. However, whenever I load more than a handful of files, this method starts skipping files. The first, say 50 files are all loaded properly but after that more and more files are skipped.
What could cause this problem, and are any better alternative methods available? This method also slows down the loading process considerably, so hopefully this process can be sped up a little bit.
EDIT: Sorry... Here's the relevant code:
private void AddItem(string file)
{
FileInfo fi = new FileInfo(file);
ListViewItem item = new ListViewItem(fi.FullName);
try
{
Image img = Image.FromFile(fi.FullName);
item.SubItems.Add(string.Format("{0} x {1}", img.Width, img.Height));
}
catch { }
((ListView)sender).Items.Add(item);
}
The try/catch methods are meant to prevent errors for non-image files. However, they also seem to be 'responsible' for the skipping issue. When I disable them I get an 'out of memory' error, which seems to be the real cause here.