我尝试在Windows窗体中实现进度条,但进度条在完成整个执行后显示结果。
public Status()
{
InitializeComponent();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while (ForReporting.FileProcessed <= ForReporting.TotalNumberFiles)
{
Thread.Sleep(100);
int temp=ForReporting.FileProcessed*100;
temp = temp / ForReporting.TotalNumberFiles;
backgroundWorker1.ReportProgress(temp);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
private void Status_Load(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}