I am trying to update 2 labels and 2 progress bars on the UI. However it does not work, the form just freezes and nothing happens until the saving is over. In windows forms I am used to using Invoke and making it update. How can I achieve updating in WPF?
Thanks!
public void EncryptFiles(string saveFileLocation, string saveFileTitle, string saveFileExtension)
{
using (ZipFile zip = new ZipFile())
{
zip.Password = passwordField1.Password;
zip.Encryption = EncryptionAlgorithm.WinZipAes256;
foreach (File file in dataStorage.listOfFiles)
{
zip.AddFile(file.fileLocation, String.Empty);
}
zip.SaveProgress += SaveProgress;
zip.Save(System.IO.Path.Combine(saveFileLocation, saveFileTitle + saveFileExtension));
}
}
public void SaveProgress(object sender, SaveProgressEventArgs e)
{
if (e.EventType == ZipProgressEventType.Saving_Started)
{
System.Windows.Forms.MessageBox.Show("Begin Saving: " + e.ArchiveName);
}
else if (e.EventType == ZipProgressEventType.Saving_BeforeWriteEntry)
{
labelCompressionStatus.Content = "Writing: " + e.CurrentEntry.FileName + " (" + (e.EntriesSaved + 1) + "/" + e.EntriesTotal + ")";
labelFilename.Content= "Filename:" + e.CurrentEntry.FileName;
progressBar2.Maximum = e.EntriesTotal;
progressBar2.Value = e.EntriesSaved + 1;
}
else if (e.EventType == ZipProgressEventType.Saving_EntryBytesRead)
{
progressBar1.Value = (int)((e.BytesTransferred * 100) / e.TotalBytesToTransfer);
}
else if (e.EventType == ZipProgressEventType.Saving_Completed)
{
System.Windows.Forms.MessageBox.Show("Done: " + e.ArchiveName);
}
}