C# “这个 BackgroundWorker 声明它不报告进度。” - 为什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9448612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"This BackgroundWorker states that it doesn't report progress." - Why?
提问by Ozarraga_AB
i am new to this backgroundworker thing
i have read some articles about how to create one
this is what it produced
我是这个后台工作者的新手,
我读过一些关于如何创建一个的文章,
这就是它产生的
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Bitmap imgbox = new Bitmap(pictureBox.Image);
int imgHeight = imgbox.Height;
int imgWidth = imgbox.Width;
int counter = 1;
MinMaxWidth = imgWidth - 50;
MaxWidth = imgWidth;
try
{
Color c;
//Color c2;
for (int i = 0; i < imgbox.Width; i++)
{
for (int j = 0; j < imgbox.Height; j++)
{
c = imgbox.GetPixel(i, j);
string cn = c.Name;
counter++;
backgroundWorker1.ReportProgress(counter);
}
}
MessageBox.Show("SUCESSFULLY DONE");
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
MyProgress.Value = e.ProgressPercentage;
}
but when i started the DoWork event. this error showed up
但是当我开始 DoWork 事件时。这个错误出现了
This
BackgroundWorkerstates that it doesn't report progress.
ModifyWorkerReportsProgessto state that it does report progress.
这
BackgroundWorker表明它不报告进度。
修改WorkerReportsProgess以声明它确实报告了进度。
ijust follow what the tutorial says
what would be the problem?, is there something that i forgot?
我只是按照教程说的那样
会有什么问题?,有什么我忘了吗?
采纳答案by Ry-
As the error suggests, set the WorkerReportsProgressproperty of your BackgroundWorkercomponent to true.
正如错误所暗示的那样,将组件的WorkerReportsProgress属性设置BackgroundWorker为true.

