This project is read-only.

Close/delete extracted files when aborting thread

May 12, 2011 at 8:39 AM

Hello,

I'm using ZevenZipExtractor to decompress a 7z archive using a background thread, as a part of a process that the user is able to interrupt. Everything works fine, except that when the user interrupts the thread I want to delete the directory created as a result of partial extraction execution. The problem is that it seems that at least one extracted file remains opened, even if I protect the extraction with a using clause (in order to dispose all decompressor resources).

Simplified code is:

public static void Decompress7zFile(String path7z, String destPath)  {

     try  {

          using (var decompressor = new SevenZipExtractor(path7z,PASSWORD_7ZIP))   {

                    decompressor .ExtractArchive(destPath);

}  

  }   catch (Exception ex)    {

        if (Directory.Exists(destPath))    Directory.Delete(destPath, true);

       throw ex;

}  }

Is there any way to ensure that no extracted files remain opened when interrupting the thread?

I work with Windows 32bits and .NET 3.5SP1.

Best regards,

Pablo