“This BackgroundWorker states that it doesn't report progress.” - Why?

家住魔仙堡 提交于 2020-01-11 19:55:12

问题


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

This BackgroundWorker states that it doesn't report progress.
Modify WorkerReportsProgess to state that it does report progress.

ijust follow what the tutorial says
what would be the problem?, is there something that i forgot?


回答1:


As the error suggests, set the WorkerReportsProgress property of your BackgroundWorker component to true.



来源:https://stackoverflow.com/questions/9448612/this-backgroundworker-states-that-it-doesnt-report-progress-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!