0

下面是我的编码:

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 冻结。有没有办法不冻结用户界面?

4

1 回答 1

2

它是否因为您显示一个对话框(msgForm.ShowDialog)而冻结?

我确实这么认为 - 只尝试Show

于 2012-09-20T08:32:35.797 回答