0
我試圖顯示進度的百分比值與標籤中的後臺工作人員.Im添加Aprox。 25 K行到一個DataTable。當我將Label.Text設置爲e.ProgressPercentage時,它工作正常。但是,當我計算百分比值,它的工人完成後仍然same.Only標籤更新爲100%計算的進度百分比未更新
progressCount = report.Rows.Count;
foreach (DataRow r in report.Rows)
{
rp.pName = r[1].ToString();
rp.batch = r[2].ToString();
rp.expr = r[3].ToString();
rp.stock = r[5].ToString();
rp.rate = r[6].ToString();
backgroundWorker2.ReportProgress(i, rp);
System.Threading.Thread.Sleep(2);
if(backgroundWorker2.CancellationPending)
{
e.Cancel = true;
backgroundWorker2.ReportProgress(0);
}
i++;
}
private void backgroundWorker2_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
metroProgressBar1.Minimum = 0;
metroProgressBar1.Maximum = progressCount;
stock st = new stock();
reportClass rp = (reportClass)e.UserState;
if(!backgroundWorker2.CancellationPending)
{
st.stockReport.Rows.Add(rp.pName, rp.batch, rp.expr, rp.stock, rp.rate);
metroProgressBar1.Value = e.ProgressPercentage;
int percn = (e.ProgressPercentage/progressCount) * 100;
metroLabel4.Text =percn.ToString();
}
}
你可能不註冊事件:backgroundWorker2.ProgressChanged + =新ProgressChangedEventHandler(backgroundWorker2_ProgressChanged); – jdweng