//Encrypt Click Function private void Encrypt_Click(object sender, RoutedEventArgs e) { try { if (destPath == "") { throw new Exception("The Destnation path is empty"); } if (srcPath == "") { throw new Exception("No File was chosen to be encrypted"); } if (password.GetText() == null) { throw new Exception("The password field is empty"); } openFilePath.IsEnabled = false; saveFilePath.IsEnabled = false; encryptBtn.IsEnabled = false; progressBar.Value = 0; progressBar.ToolTip = 0; label.Visibility = Visibility.Visible; MessageBoxResult result = MessageBox.Show("Do you want to delete the orignal file?\nThe file will be deleted if and when the process will finsih successfully", "Delete the orignal file", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (result == MessageBoxResult.Cancel) { return; } new Task((password) => { try { vault.EncryptFile(srcPath, destPath, password.ToString(), MessageBoxResult.Yes == result); Dispatcher.Invoke(() => { progressBar.Value = 100; MessageBox.Show("The File has been encrypted successfully.\n" + destPath, "File Encrypted", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK); this.Close(); }); } catch (Exception ex) { Dispatcher.Invoke(() => { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); }); } }, password.GetText()).Start(); new Task(() => { double progress = 0; while (progress < 99.8) { Thread.Sleep(20); progress = vault.GetPrecntegeOfProcess(); Dispatcher.Invoke(() => { progressBar.Value = progress; progressBar.ToolTip = Math.Round(progress, 2); }); } }).Start(); //vault.EncryptFile(srcPath, destPath, password.GetText()); //this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); } }