[英]C# backgroundwork / progress bar not updating
string[] idit = File.ReadAllLines(textBox2.Text);
foreach (string barcoutn in idit){
barcountmax++;
}
foreach (string ids in idit){
//do sql stuff
barmovement++;
bgw1.ReportProgress(barmovement);
}
private void bgw1_ProgressChanged(object sender, ProgressChangedEventArgs e){
progressBar1.Value = e.ProgressPercentage;
}
My progressbar properties are set from the barcountmax for the max value and min value = 0. 我的进度栏属性是从barcountmax设置为最大值和最小值= 0。
I can't seem to get my progress bar to update, what am i missing? 我似乎无法更新进度条,我想念什么?
Right now, you only update at the end 现在,您只在最后更新
foreach (string ids in idit)
{
//do sql stuff
barmovement++;
}
bgw1.ReportProgress(barmovement);
You need to update as you go: 您需要随时更新:
foreach (string ids in idit)
{
//do sql stuff
barmovement++;
bgw1.ReportProgress(barmovement);
}
You need to call ReportProgress with an int value from 0 to 100. If you're calling it with barmovement
directly, this is potentially a problem. 您需要使用介于0到100之间的int值来调用ReportProgress 。如果直接使用
barmovement
调用它,则可能存在问题。 For details, see the help for ReportProgress : 有关详细信息,请参见ReportProgress的帮助:
percentProgress
percentProgress
Type: System.Int32
类型:System.Int32
The percentage, from 0 to 100, of the background operation that is complete.
完成的后台操作的百分比,从0到100。
Did you set WorkerReportsProgress
to true? 您是否将
WorkerReportsProgress
设置为true? It is false by default. 默认情况下为false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.