I'm having this really weird problem and wanted to see if you guys could give me some advice here. I want to load an image into an image control from a specific file URI, but I want to have the option to delete the file from the file system as well. The problem is that I keep getting this error:
"The process cannot access the file 'c:\38.gif' because it is being used by another process."
Here is my code (VB.NET but C# solutions will be helpful as well!):
'to load the image
Dim bitmap1 as New BitmapImage
bitmap1.BeginInit()
bitmap1.UriSource = New Uri("c:\38.gif", UriKind.Absolute)
bitmap1.EndInit()
Image1.Source = bitmap1.Clone
And then if the user clicks a button, I want to delete that particular file like this:
Image1.Source = Nothing
File.Delete("c:\38.gif")
Anyone have any idea how I can load the image yet still be able to delete the source file??
Many thanks in advance!