How to: Cancel Archivation
To provide the capability to cancel an archiving process after it has been started, do the following:
- Create a ZipArchive class instance.
- Subscribe to the ZipArchive.Progress event.
- Set the CanContinueEventArgs.CanContinue property of event arguments to false, in case you decide to stop the operation.
- Call the ZipArchive.AddFile method for each selected file.
- Call the ZipArchive.Save method to create an archive and save it to a specified location.
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;
}