title: C# WPF deleting images after use
body: <p>I have an that turns on a webcam and takes a picture of a barcode; this part works fine but I now want to display the picture taken on screen.</p>
  
  <p>I have created the image control in the axml file as follows:</p>
  
  <pre><code>&lt;Image x:Name="BarcodeImage" Margin="5" Height="240" Width="450"/&gt;
  </code></pre>
  
  <p>As you can see I haven't actually set an image yet as there is nothing to show.</p>
  
  <p>Once the picture has been taken, I save the image to my hard-drive; this works correctly as I can view the image from my PC.</p>
  
  <p>I am then setting the image in code as follows:</p>
  
  <pre><code>this.BarcodeImage.Source = new BitmapImage(new Uri(filename));
  </code></pre>
  
  <p>This works correctly and I can now see the taken image on the screen.</p>
  
  <p>My problem occurs if I wish to scan a different barcode; I cannot save the next picture taken as the filename already exists so I am trying to delete the picture before saving the next but I keep getting the error message "the file may be in use by another process".</p>
  
  <p>I have tried having a default image that I set to before deleting (hoping that image I want to delete is now not being used), but now both images cannot be deleted (even manually) as they are both being used by another process.</p>
  
  <p>I have also tried setting the image.source to null, but this does not work either.</p>
  
  <p>Do you have any suggestions on how I can delete my image or to clear the current image set?</p>