File in use after dispose?

Nov 12, 2008 at 11:03 AM
If you have a large file and when you are extracting it there is not enough space on disk (say you are extracting a 1GB file to a USB drive with 500MB free), an exception is thrown (as expected) but in that exception you cannot delete the file currently being extracted.

I tried calling dispose but that does not help. Whatever has that file open, still has the file open after calling dispose (which surprised me).

Any way around this?

Here is some sample code. Of course, with this code you should never encounter such a problem but someone else could write to the drive after you start ExtractAll and before ExtractAll completes.

            Using zip As New Ionic.Utils.Zip.ZipFile(TextBox2.Text)
                Dim lngTotal As Long = 0
                For Each entry As Ionic.Utils.Zip.ZipEntry In zip
                    lngTotal += entry.UncompressedSize
                Dim boolEnoughSpace As Boolean = True
                Dim strDrive As String = System.IO.Path.GetPathRoot(TextBox3.Text)
                If strDrive.Contains(":") Then
                    Dim di As New System.IO.DriveInfo(strDrive)
                    If di.AvailableFreeSpace > lngTotal Then
                        boolEnoughSpace = True
                        boolEnoughSpace = False
                    End If
                End If
                Console.WriteLine("Total: " & lngTotal.ToString("#,##0"))

                If boolEnoughSpace Then
                    MessageBox.Show("Not enough space")
                End If
            End Using

        Catch ex As Exception
            If ex.Message.Contains("There is not enough space on the disk.") Then
                System.IO.Directory.Delete(TextBox3.Text, True)
                MessageBox.Show("Error: " & ex.Message)
            End If
        End Try

Nov 12, 2008 at 3:09 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.