Back to Devexpress

ZipArchive.Progress Event

officefileapi-devexpress-dot-compression-dot-ziparchive-9128c6a3.md

latest5.2 KB
Original Source

ZipArchive.Progress Event

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

Namespace : DevExpress.Compression

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public event ProgressEventHandler Progress
vb
Public Event Progress As ProgressEventHandler

Event Data

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

PropertyDescription
CanContinueGets or sets the value that specifies whether the process can proceed further. Inherited from CanContinueEventArgs.
ProgressObtains 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.

View Example

csharp
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;
        }
vb
Imports DevExpress.Compression
'INSTANT VB TODO TASK: There is no VB.NET equivalent to 'volatile':
'ORIGINAL LINE: volatile bool stopProgress = False;
        Private stopProgress As Boolean = False

        Public Sub CancelArchiveProgress()
            Dim sourcefiles() As String = Me.sourceFiles
            Using archive As New ZipArchive()
                AddHandler archive.Progress, AddressOf archive_Progress
                For Each file As String In Me.sourceFiles
                    archive.AddFile(file, "/")
                Next file
                archive.Save("Documents\CancelArchiveProgress.zip")
            End Using
        End Sub

        Private Sub archive_Progress(ByVal sender As Object, ByVal args As ProgressEventArgs)
            args.CanContinue = Not Me.stopProgress
        End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Progress event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

zip-compression-and-archive-api-examples/CS/CompressionLibraryExamples/ZipExamples.cs#L112

csharp
using (ZipArchive archive = new ZipArchive()) {
    archive.Progress += archive_Progress;
    foreach (string file in sourceFiles) {

zip-compression-and-archive-api-examples/VB/CompressionLibraryExamples/ZipExamples.vb#L117

vb
Using archive As New ZipArchive()
    AddHandler archive.Progress, AddressOf archive_Progress
    For Each file As String In Me.sourceFiles

See Also

ZipArchive Class

ZipArchive Members

DevExpress.Compression Namespace