Hi there,
I am trying to delete image files from static collection of images and every time It throws an IO Exception {"The process cannot access the file D:\... because it is being used by another process."}. This is the sample of my code.
Here the ThumbnailFactory is the static class with a collection of images ThumbnailInfo.
// Local collection to hold the list of files to be deleted
List<string> lstRemove = new List<string>();
foreach (ListViewItem lstItem in this.etListView.SelectedItems)
{
FileInfo fileInfo = lstItem.Tag as FileInfo;
this.AssetListView.Items.Remove(this.AssetListView.SelectedItems[0]);
foreach (ThumbnailFactory.ThumbnailInfo ti in ThumbnailFactory.ActiveThumbnails)
if (ti.Path == fileInfo.FullName)
{
ThumbnailFactory.ActiveThumbnails.Remove(ti);
break;
}
lstRemove.Add(fileInfo.FullName);
}
etListView.SelectedItems.Clear();
foreach (string fName in lstRemove)
System.IO.File.Delete(fName);
The Error occurs in the last line when the method "System.IO.File.Delete(fName);" is called. Strangle it happens only when the file type is an image.
When I ran sysinternals "handle" utility to see which process was holding refence to the file it is listed under my application exe in Section \BaseNamedObjects\netfxcustomperfcounters.1.0.net clr networking .... any Bells !!
Would be glad if some one could help me !
- Paul