Deleting an Image that has been used by a WPF control

Posted by Peter on Stack Overflow See other posts from Stack Overflow or by Peter
Published on 2010-03-11T08:53:15Z Indexed on 2010/03/13 5:15 UTC
Read the original article Hit count: 341

Filed under:
|
|

Hi,

I would like to bind an Image to some kind of control an delete it later on.

path = @"c:\somePath\somePic.jpg"
FileInfo fi = new FileInfo(path);
Uri uri = new Uri(fi.FullName, UriKind.Absolute);
var img = new System.Windows.Controls.Image();
img.Source = new BitmapImage(uri);

Now after this code I would like to delete the file :

fi.Delete();

But I cannot do that since the image is being used now. Between code fragment 1 en 2 what can I do to release it?

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf