title: WPF Image Caching
body: <p>I have a WPF application that takes a snapshot image from a video file. The user can define the timestamp from which to take the image. The image is then saved to a temporary location on disk, and is then rendered into an <code>&lt;image&gt;</code> element.</p>
  
  <p>The user should then be able to select a different timestamp, which then overwrites the temporary file on disk - this should then be displayed within the <code>&lt;image&gt;</code> element.</p>
  
  <p>Using <code>Image.Source = null;</code>, I can <em>clear</em> the image file from the <code>&lt;image&gt;</code> element, so it displays a blank space instead. However, if the source image file is then overwritten with a new image (with the same name) and loaded into the <code>&lt;image&gt;</code> element, it <strong>still shows the old image</strong>.</p>
  
  <p>I am using the following logic:</p>
  
  <pre><code>// Overwrite temporary file file here
  
  // Clear out the reference to the temporary image
  Image_Preview.Source = null;
  
  // Load in new image (same source file name)
  Image = new BitmapImage();
  Image.BeginInit();
  Image.CacheOption = BitmapCacheOption.OnLoad;
  Image.UriSource = new Uri(file);
  Image.EndInit();
  Image_Preview.Source = Image;
  </code></pre>
  
  <p>The image displayed in the <code>&lt;image&gt;</code> element does not change, even though the original file has been completely replaced. Is there an image caching issue here that I am not aware of?</p>