I am fairly new to C# and coding in general so some of this might be going about things the wrong way. The program I wrote works and compresses the file as expected, but if
Using ZipFile.CreateFromDirectory you can create a kind of progress based on the size of the output file. Using the compression in another thread (Task.Run) you should be able to update your UI and make it responsive.
void CompressFolder(string folder, string targetFilename)
{
bool zipping = true;
long size = Directory.GetFiles(folder).Select(o => new FileInfo(o).Length).Aggregate((a, b) => a + b);
Task.Run(() =>
{
ZipFile.CreateFromDirectory(folder, targetFilename, CompressionLevel.NoCompression, false);
zipping = false;
});
while (zipping)
{
if (File.Exists(targetFilename))
{
var fi = new FileInfo(targetFilename);
System.Diagnostics.Debug.WriteLine($"Zip progress: {fi.Length}/{size}");
}
}
}
This works 100% if you have CompressionLevel to NoCompression. With compression it would work partly based on the ending size of the zip file. But it will show that something is happening, so when the file is done, jump from whatever percentage of progress to 100%.