.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

ZipArchive.Progress Event

Occurs evenly while the items are being compressed to indicate progress.

Namespace: DevExpress.Compression

Assembly: DevExpress.Docs.v21.1.dll

Declaration

public event ProgressEventHandler Progress

Event Data

The Progress event's data class is ProgressEventArgs. The following properties provide information specific to this event:

Property Description
CanContinue Gets or sets the value that specifies whether the process can proceed further. Inherited from CanContinueEventArgs.
Progress Obtains the progress value.

Remarks

By handling the Progress event, you can obtain information about the progress of zipping the archive items. You can also interrupt archive creation by setting the CanContinueEventArgs.CanContinue value to false. After that, the archive is saved with all items which have been zipped to that point and the process is finished.

The following code snippet illustrates how you can use the volatile variable to interrupt archive creation at any time. When the Progress event occurs, the event handler checks for the stopProgress value. If it is true, the process stops.

using DevExpress.Compression;
        volatile bool stopProgress = false;

        public void CancelArchiveProgress() {
            string[] sourcefiles = this.sourceFiles;
            using (ZipArchive archive = new ZipArchive()) {
                archive.Progress += archive_Progress;
                foreach (string file in sourceFiles) {
                    archive.AddFile(file, "/");
                }
                archive.Save("Documents\\CancelArchiveProgress.zip");
            }
        }

        private void archive_Progress(object sender, ProgressEventArgs args) {
            args.CanContinue = !this.stopProgress;
        }
See Also