officefileapi-15242-zip-compression-and-archive-api-examples-how-to-cancel-archiving.md
To provide the capability to cancel an archiving process after it has been started, do the following:
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;
}
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