Deleting a file in C# fails
<p>I have a code that downloads an image from the internet, and caches it locally. It also allows an alternative by allowing the user to select his own image, which is copied to the cache and resized to the codes needs.
A problem occurs when I try to empty that cache programatically. all images downloaded by the code are deleted just fine, but when it tries to delete user selected images, an exception is thrown stating that I dont have permission to do so.
The images are not loaded when the cache clearing occurs (they are being disposed, and the garbage collector is forced to run afterwards), so I assume its not a conflict due to the image being opened by the program.
What may cause such behavior, and how can I work around it?\</p>

<pre><code>        DirectoryInfo cacheDir = new DirectoryInfo(strCacheDir);

        //Delete any jpeg-s in the cache dir
        foreach (FileInfo file in cacheDir.GetFiles())
        {
            if (file.Extension == ".jpg")
            {
                file.Delete();
            }
        }
</code></pre>
