我有简单的 winforms 应用程序,其中有按钮。点击按钮我正在做这样的事情
private void Button1_Click(object sender, EventArgs e)
{
BackgroundWorker bw_Convert = new BackgroundWorker();
bw_Convert.WorkerReportsProgress = true;
bw_Convert.DoWork += bw_Convert_DoWork;
bw_Convert.RunWorkerCompleted += bw_Convert_RunWorkerCompleted;
bw_Convert.ProgressChanged += bw_Convert_ProgressChanged;
bw_Convert.WorkerReportsProgress = true;
bw_Convert.RunWorkerAsync();
}
我有以下后台工作人员代码
public void bw_Convert_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i <= 1000000; i++)
{
bw_Convert.ReportProgress((100 * (i) / 1000));
}
}
public void bw_Convert_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBarControl1.EditValue = e.ProgressPercentage.ToString();
}
通过做这个。为什么我的主线程在处理后台工作人员中的事情时被挂起。