0

I do the following (simplified) in my code :

this.ImageComponent.Source = new BitmapImage(new Uri("myImage.jpg", UriKind.Absolute));

I have a button and when I click it I do the following :

this.ImageComponent.Source = new BitmapImage(new Uri("anotherImage.jpg", UriKind.Absolute));
System.IO.File.Delete("myImage.jpg");

But I have an exception on the delete, it says it can access the file because it is used by another process. (I've tried with full and relative path).

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user2088807
  • 1,378
  • 2
  • 25
  • 47
  • Check this: http://stackoverflow.com/questions/8352787/how-to-free-the-memory-after-the-bitmapimage-is-no-longer-needed you may need to free your `BitmapImage` – Joel Legaspi Enriquez Aug 11 '15 at 08:17
  • Refer [this](http://stackoverflow.com/questions/7094684/c-sharp-wpf-how-to-unreference-a-bitmapimage-so-i-can-delete-the-source-file) and [this](http://stackoverflow.com/questions/6430299/bitmapimage-in-wpf-does-lock-file). Both are probable duplicates – Sriram Sakthivel Aug 11 '15 at 08:18

0 Answers0