I've read probably all the post regarding this. Can't seem to find the problem. this is my collection
private ObservableCollection<BitmapImage> _imageList = new ObservableCollection<BitmapImage>();
And this is how i load my images
foreach (string filepath in temp) //populate image collection
{
BitmapImage tempImg = new BitmapImage();
tempImg.BeginInit();
tempImg.CacheOption = BitmapCacheOption.OnLoad;
tempImg.UriSource = new Uri(filepath);
tempImg.EndInit();
_imageList.Add(tempImg);
}
The exception happens at the line when i try to delete, the file is in use.
if (File.Exists(_imageList[SelectedItem].UriSource.AbsolutePath.ToString()))
{
int temp = SelectedItem;
//_imageList.RemoveAt(temp);
Console.WriteLine(_imageList[temp].UriSource.AbsolutePath.ToString());
File.Delete(_imageList[temp].UriSource.AbsolutePath.ToString());
}
The Exception:
An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code.
Additional information: The process cannot access the file 'e:\pix\img.jpg' because it is being used by another process.
Can someone please reopen it? I figured out the problem, and it's not this code, it was in the section of the View, i would like to post an answer.