I have a custom window named ImageWindow, which has a Image
control in it.
public void DownloadImageWithExtension(Uri url, ImageFormat format)
{
if (File.Exists(path))
{
File.Delete(path));
}
using (WebClient client = new WebClient())
{
client.DownloadFile(url, path);
}
ImageWindow iw = new ImageWindow(path);
iw.ShowDialog();
}
This is my main windows code, which calls ImageWindow (iw) passing the file to open, which has been downloaded.
public partial class ImageWindow : Window
{
public ImageWindow(string fileName)
{
InitializeComponent();
BitmapImage image = new BitmapImage(new Uri(fileName));
image_Image.Source = image; //Set Image controls image source to BitmapImage
}
}
Here i get the image, save it to BitmapImage
and add to Source
of the Image
control inside the newly opened window.
After i close the window and try to open the window again, i get this I/O exception.
The process cannot access the file '\bin\Debug\10supercomfywallpapers!.Jpeg' because it is being used by another process.
I have found some fixes mentioning using dispose and such, but BitmapImage
doesn't inherit IDisposable
.
EDIT: The deletion will be moved to after the OpenDialog() returns, but i need to fix the window not disposing first to do that.