我有一个问题,我正在使用backgroundWorker1.RunWorkerAsync()
on button_click 方法,并且还使用backgroundWorker1_DoWork()
,backgroundWorker1_ProgressChanged()
事件,所有事件都在触发,但进度条没有刷新。这是我的代码:
private void btnMove_Click(object sender, EventArgs e)
{
try
{
backgroundWorker1.RunWorkerAsync();
for (int i = 0; i < gdFiles.Rows.Count - 1; i++)
{
// my process
}
catch (Exception ex)
{
}
}
}
事件是
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i <= 100; i++)
{
backgroundWorker1.ReportProgress(i);
Thread.Sleep(100);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
progressBar1.Refresh();
}
任何人都可以请帮助解决这个问题......