FileSystemWatcher locks file, how to release it?
<p>I am using a FileSystemWatcher to raise the event when an image file is edited on Paint and update the preview image control using it. But setting the file as a source second time, it throws an error because the file is still in use by another process. So I discovered this is because of FileSystemWatcher.</p>

<p><strong>I have this code:</strong></p>

<pre><code>    private void btnEdit_Click(object sender, RoutedEventArgs e)
    {
        if (!File.Exists(lastImage)) return;
        FileSystemWatcher izleyici = new FileSystemWatcher(System.IO.Path.GetDirectoryName( lastImage),
            System.IO.Path.GetFileName(lastImage));
        izleyici.Changed += izleyici_Changed;
        izleyici.NotifyFilter = NotifyFilters.LastWrite;
        izleyici.EnableRaisingEvents = true;
        ProcessStartInfo info = new ProcessStartInfo();
        info.FileName = lastImage;
        info.Verb = "edit";
        Process.Start(info);
    }

    void izleyici_Changed(object sender, FileSystemEventArgs e)
    {
       //I want to add code here to release the file. Dispose() not worked for me

       setImageSource(lastImage);
    }

    void setImageSource(string file)
    {
        var bitmap = new BitmapImage();

        using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            bitmap.BeginInit();
            bitmap.CacheOption = BitmapCacheOption.OnLoad;
            bitmap.StreamSource = stream;
            bitmap.EndInit();
        }

        ssPreview.Source = bitmap;
    }
</code></pre>

<p>In this code I want to release the file before updating the <code>Image</code> control. I tried <code>Dispose</code> but it was not worked. How can I do that?</p>