This project is read-only.

Any way to address DNZ while it is processing the file list?

Apr 19, 2011 at 12:42 AM

What I would like to do is have the ability to cancel zipping operations while DNZ is "processing" the file list; scanning the directory I send it so that it knows what files to add. This operation can take several seconds for a folder with several thousand files, and I would like a way to cancel it. Right now, if I press cancel, it will not cancel until just before the first file is zipped.



I'm using this code:


(Zip sub) -- AddHandler Zip.SaveProgress, New EventHandler(Of SaveProgressEventArgs)(AddressOf Zip_SaveProgress)


    Private Sub Zip_SaveProgress(ByVal sender As Object, ByVal e As SaveProgressEventArgs)
        If bwBackup.CancellationPending Then e.Cancel = True 'If we press the stop button, invoke Cancel. RunWorkerCompleted will be called.

        Select Case e.EventType
            Case ZipProgressEventType.Saving_AfterWriteEntry
                SetStatusText("(" & cCount & "/" & cTotal & ") " & lang_Compressing & " " & CheckedText.Replace(" - ", ": ") & Environment.NewLine & CInt(Math.Truncate(100 * (e.EntriesSaved / e.EntriesTotal))) & lang_CompletePercentageCap)
        End Select

    End Sub


This code works only if the backup has started (I know this behavior is intended). I attempted to use a Zip.ReadProgress handler, but that appears to only be for extracting. I've attempted to add more cases to the block, for instance, ZipProgressEventType.Saving_Started, but that was not working, either.


To be more specific, the code I tried functions, but it is not doing what I need it to do. Is it possible to address DNZ while it is processing the file list?

Apr 19, 2011 at 5:52 PM
Edited Apr 19, 2011 at 8:18 PM

Yes, there is an "AddProgress" event, very similar to the SaveProgress event you are already using.  Whereas SaveProgress gets called during the course of saving a zip file, AddProgress gets called during the process of adding file entries to the ZipFile instance. AddProgress is designed specifically for the issue you described.

The documentation: 


Apr 19, 2011 at 10:02 PM

Thanks for the link. The AddProgress event is working, but I am unable to cancel the operation.


I tried both of these handlers seperately:

                    'AddHandler Zip.AddProgress, New EventHandler(Of AddProgressEventArgs)(AddressOf Zip_AddProgress)
                    AddHandler Zip.AddProgress, AddressOf Zip_AddProgress


    Private Sub Zip_AddProgress(ByVal sender As Object, ByVal e As AddProgressEventArgs)

        If bwBackup.CancellationPending Then e.Cancel = True 'If we press the stop button, invoke Cancel. RunWorkerCompleted will be called.

        Select Case e.EventType
            Case ZipProgressEventType.Adding_Started
                'code removed; update status label here.
                Exit Select
            Case ZipProgressEventType.Adding_AfterAddEntry
                'code removed; update status label here.
                'e.Cancel = True
                Exit Select
        End Select

End Sub


The labels update as expected, and the message box fires constantly, as I would expect it to. However, e.Cancel is not working. Bypassing the background worker and directly cancelling the operation in Adding_AfterAddEntry (now commented out), did not work either. The operation continues until the SaveProgress phase, where it is cancelled immediately due to the previous call to bwBackup.CancelAsync.

Apr 20, 2011 at 12:27 AM

Hmmmmm, that sounds like a bug!

Apr 20, 2011 at 12:28 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 21, 2011 at 12:13 AM

If the adding process cannot be cancelled through e.Cancel, what is the second best way to do it?

If bwWorker.CancellationPending Then Exit Sub -- does not speed up the process.

Would bwWorker.Dispose be the only other option in this case?

Apr 21, 2011 at 2:51 PM

I guess the second way to do it would be to add the files yourself, in your own app code.

Get the list of 1000's of files yourself (do a Directory.GetFiles()), then add files into the ZipFile in chunks, and periodically check CancellationPending. If it is true, then halt the zip process, exit the using clause for the ZipFile, and let the backgroundWorker complete.