Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All

I have a canvas that displays images. These images supposed to be updated at run time. Update happens when the image is already display and the next image in the qeue is being displayed. However I am not able to delete nor modify the previously displayed images since I get the "file is being used by another process" exception. It seems like Canvas still has its grip on the previously displayed files. I tried canvas.children.clear() but it didn't help. Does anyone one know how to remove that link (close file or...)?
 Uri newUri = new Uri(@inputA);
 Image.ImageSource = new BitmapImage(newUri);

ImageCanvas.Children.Clear();  // this didnt help
Posted

1 solution

hi
your application itself holding that file so we need to use filestream etc like below

C#
FileInfo fileinfo = new FileInfo(filepath);
  if (fileinfo.Exists)
   {
      using (FileStream fs = System.IO.File.Open(filepath,
                                                  FileMode.Open,
                                                  FileAccess.Read,
                                                  FileShare.ReadWrite))
       {
          using (StreamReader reader = new StreamReader(fs))
           {  
              BitmapImage bitImg = new BitmapImage()
              bitImg.StreamSource=reader ;
              Image.ImageSource= bitImg; 
             }
        }
   }

Regards
Siraz
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900