I guess you are using DotNetZip ?
There are numerous issue in the code you've shown:
- you don't call ReportProgress in
DoWork
so how do you expect to get the progress ?
- even if you did so the problem is with
zip.Save()
you wouldn't get a progress (beside 100%) because it would not return unless it is finished.
Solution
Use tasks and SaveProgress
event instead :
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
await Task.Run(() =>
{
using (var zipFile = new ZipFile())
{
// add content to zip here
zipFile.SaveProgress +=
(o, args) =>
{
var percentage = (int) (1.0d/args.TotalBytesToTransfer*args.BytesTransferred*100.0d);
// report your progress
};
zipFile.Save();
}
});
}
Doing this way, your UI will not freeze and you will get a periodic report of the progress.
Always prefer Tasks over BackgroundWorker
since it's official approach to use now.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…