根据进程pourcentage动态更新进度条Value C#

Update progress bar Value dynamically according to process pourcentage C#

我创建了一个应用程序,我在其中从 excel 文档中读取数据。我正在使用后台工作人员完成所有耗时的任务。我如何显示进度条中完成了多少百分比的工作?

我知道那里有 Report_Progress 事件,但这是否意味着我需要指定硬编码值?

有什么方法可以让我知道完成的工作占总工作量的百分比吗?

我想说明的一个例子是在复制时如何 window 显示进度条并根据复制的数据百分比增加。

请帮帮我

谢谢

BackgroundWorker backgroundWorker = new BackgroundWorker();

backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.WorkerSupportsCancellation = true;
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);

void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{ 
    backgroundWorker.ReportProgress(yourprogress);
}

void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
             Messagebox.show(e.ProgressPercentage.toString())
             /// update you progressbar here with e.ProgressPercentage
             progressBar.Value = e.ProgressPercentage;

}

你可以再找一个例子here