您正在尝试为我的加密和压缩应用程序加载进度条。 我正在尝试使用后台工作程序来更新压缩和加密处理所用时间的进度条,但不知何故应用程序显示我已包含在按钮内而不是成功的加密失败消息框。
这是我按钮的代码
private void lockButton_Click(object sender, EventArgs e)
{
if (this.passwordtextBox.Text == "")
{
MessageBox.Show("Please enter a password!");
}
else if (this.retypeTextBox.Text == "")
{
MessageBox.Show("Please retype password!");
}
else if (this.passwordtextBox.Text == this.retypeTextBox.Text)
{
details = new Details();
details.SetPassword(this.passwordtextBox.Text);
if (this.EncryptionComboBox.Text == "AES")
{
details.SetEncryption(this.EncryptionComboBox.Text);
if (details.GetResult() == true)
{
// Start the background worker
backgroundWorker1.RunWorkerAsync();
}
if (details.GetResult() == true)
{
MessageBox.Show("Lock Success!");
}
else
{
MessageBox.Show("Lock Unsuccess! Please try again");
}
}
}
else
{
MessageBox.Show("The password and verified password does not match!");
}
}
这是我的后台工作人员代码
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
//declare lockcontroller to be used
LockController lControl = new LockController();
//run zipfile method and store result to fName
lControl.compress(ifile, details);
lControl.Encrypt(details);
lControl.LockCleaner(details);
int i = 100;
// Report progress to 'UI' thread
backgroundWorker1.ReportProgress(i);
// Simulate long task
System.Threading.Thread.Sleep(0000);
}
我想知道它出了什么问题。进度条和加密都不起作用..
答案 0 :(得分:3)
答案 1 :(得分:2)
执行此行backgroundWorker1.RunWorkerAsync();
时
它会立即返回并执行下一行。您需要为消息框订阅RunWorkerCompleted事件。