如何在使用c#和System.IO.Compression压缩zip文件时取得进展
我需要在使用C#with System.IO.Compression压缩zip文件时获取%。 我有以下代码:如何在使用c#和System.IO.Compression压缩zip文件时取得进展,c#,zipfile,system.io.compression,C#,Zipfile,System.io.compression,我需要在使用C#with System.IO.Compression压缩zip文件时获取%。 我有以下代码: if (isDirectory) { Invoke(new RefreshConsoleEncryptionDel(RefreshConsoleEncryption), "[+]Wait, compressing folder..."); ZipFile.CreateFromDirectory(FileNam
if (isDirectory) {
Invoke(new RefreshConsoleEncryptionDel(RefreshConsoleEncryption), "[+]Wait, compressing folder...");
ZipFile.CreateFromDirectory(FileName, FileName + "_DirEnc.zip");
Invoke(new RefreshProcessBar1Del(RefreshProcessBar1), 100);
Invoke(new RefreshConsoleEncryptionDel(RefreshConsoleEncryption), "[✓]COMPLETED");
Invoke(new RefreshConsoleEncryptionDel(RefreshConsoleEncryption), "[K]Starting encrypting file...");
byte[] BytePasswordArray = IsFile ? File.ReadAllBytes(Password) : Encoding.UTF8.GetBytes(Password); // We create the array who will contain all bytes of password, depending if its an file password or just a string;
// A simple ternary condition, who checks if is file or string password
FileEncryptProcess(5000000, FileName + "_DirEnc.zip", BytePasswordArray); // We call the function to encrypt the file.
// If all goes allright we continue, else this thread will be aborted and we cant continue to next line.
Thread.CurrentThread.Abort();// If we can continue, then all will be allright and we close this thread succesfully.
}
我需要更新ProgressBar1,其中包含压缩所占的百分比。
有可能吗 通常通过事件或回调方法报告进度。我不熟悉System.IO.Compression,但是快速浏览文档似乎没有显示任何采用回调方法的事件或方法。所以可能有公开的方法可以在这个特定的库上取得进展。Thx Mason,但我最终找到了一个解决方案!我用了这条线: