问题描述
我已经在C#WinForms应用程序中创建了一个加载表单,该加载表单在长时间的过程中会显示出来。 我已经在加载表单中添加了一个进度条,我想对其进行更新以向用户提供一些加载反馈。
在加载表单代码中,我创建了一个新的BackgroundWorker并添加了DoWork和ProgressChanged事件处理程序。 问题是没有调用backgroundWorker_ProgressChanged。我已经在函数中插入了断点,但是它们没有被捕获。
我要去哪里错了?任何帮助表示赞赏。谢谢。
frmLoading:
public frmLoading()
{
InitializeComponent();
//check if bg worker is null
if (backgroundWorker == null)
{
backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += backgroundWorker_DoWork;
backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged;
}
backgroundWorker.WorkerReportsProgress = true;
//start
backgroundWorker.RunWorkerAsync();
}
backgroundWorker_DoWork:
private void backgroundWorker_DoWork(object sender,DoWorkEventArgs e)
{
for (int i = 1; i <= 100; i++)
{
Thread.Sleep(100);
backgroundWorker.ReportProgress(i);
}
}
backgroundWorker_ProgressChanged:
private void backgroundWorker_ProgressChanged(object sender,ProgressChangedEventArgs e)
{
//update value of progress bar
progressBar1.Value = e.ProgressPercentage;
//set the text of the progress bar
this.Text = e.ProgressPercentage.ToString();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)