ASP.NET Delete file after exception in TransmitFile
<p>I have following code:</p>

<pre><code>try
{
    context.Response.TransmitFile(savedFileName);
}
catch (Exception ex)
{
    ExceptionUtility.LogException(new Exception("Exception while transmit zip [AttachmentsSecurityHandler.cs]: " + ex.Message), false);
}
finally
{
    try
    {
        Thread.Sleep(500);
        File.Delete(savedFileName);
    }
    catch (Exception ex)
    {
        ExceptionUtility.LogException(new Exception("Unable to delete temp zip file [AttachmentsSecurityHandler.cs]: " + ex.Message), false);
    }
}
</code></pre>

<p>Everything works fine, only when user cancels download I get:</p>

<pre><code>Exception while transmit zip [AttachmentsSecurityHandler.cs]: The remote host closed the connection. The error code is 0x800703E3.
Unable to delete temp zip file [AttachmentsSecurityHandler.cs]: The process cannot access the file 'D:\Hosting\***\html\attachments\tempCompressed\b9b5c47e-86f9-4610-9293-3b92dbaee222' because it is being used by another process.
</code></pre>

<p>Is only way to delete orphaned files is to try to delete old (for example hour old) files? How long system will keep lock (GoDaddy shared hosting)? Thank you.</p>
