Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 345
Ozarraga_AB Avatar asked Feb 25 '12 22:02

Ozarraga_AB


People also ask

What is use of BackgroundWorker in C#?

BackgroundWorker makes the implementation of threads in Windows Forms. Intensive tasks need to be done on another thread so the UI does not freeze. It is necessary to post messages and update the user interface when the task is done.

What is BackgroundWorker?

The BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running.

What is BackgroundWorker in Winforms?

The BackgroundWorker class exposes the DoWork event, to which your worker thread is attached through a DoWork event handler. The DoWork event handler takes a DoWorkEventArgs parameter, which has an Argument property.

How do I restart my BackgroundWorker?

By creating a Task , the backgroundworker is can be stopped with the CancelAsync and restarted inside the Task. Not making a Task wil start the backgroundworker again before it is cancelled, as the OP describes.


1 Answers

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

like image 163
Ry- Avatar answered Sep 19 '22 23:09

Ry-