以下是我的编码:
Form2 msgForm;
private void button3_Click_1(object sender, EventArgs e)
{
bw.WorkerReportsProgress = true;
bw.WorkerSupportsCancellation = true;
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
//bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
msgForm = new Form2();
try
{
bw.RunWorkerAsync(comboBox15.Text);
msgForm.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
string PrtAdd = e.Argument.ToString();
uploadlogo(PrtAdd);
// uploadlogo(PrtAdd) is the coding that transmit serial protocol and will last around 2 minutes to finish.
}
void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
msgForm.Close();
}
我的编码用于在单击按钮时运行后台工作程序,因为单击按钮将传输协议,大约需要2分钟。
在这2分钟内,它将显示"请等待"在form2。
问题是,当我运行此编码并单击按钮运行后台工作程序时,我的winform UI冻结。有没有办法不冻结用户界面?
答案 0 :(得分:2)
是否会冻结,因为您显示了一个对话框(msgForm.ShowDialog
)?
我确实这么认为 - 只尝试Show