Possible Duplicate:
C# 4.0 unlock image after creating BitmapImage
I have this code to create an Image file in WPF.
var newimage = new System.Windows.Controls.Image
{
Stretch = Stretch.Fill,
StretchDirection = StretchDirection.Both,
Width = Width,
Height = Height
};
var logo2 = new BitmapImage();
logo2.BeginInit();
logo2.UriSource = uri;
logo2.EndInit();
newimage.Source = logo2;
After this some process have to delete ol file and create a new one but I'm facing an error
"Cannot delete file because it is being used by another process"
What should I do to fix this issue?
Thank you!
P.S.
I delete the file using this:
try
{
if (File.Exists(fileName))
{
File.Delete(fileName);
Debug.WriteLine("FILE MANAGER: File " + fileName + " has been deleted.");
}
return true;
}