I have a problem with a component "BackgroundWorker"
When I click on a button I have to perform n iterations that take time and I have to delegate this operation to another thread
I followed this tutorial: tutorial (in french)
Here is my code:
private void btnIterate_Click(object sender, EventArgs e)
{
bgwIterer.RunWorkerAsync();
}
private void bgwIterer_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
e.Result = new Iterate(btnIterate, btnReinit, txtInput, lblState, entree, worker, e);
}
private void bgwIterer_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.lblState.Text = e.ProgressPercentage;
}
bgwIterer is my BackgroundWorker component and here is the method I would like to delegate:
class Iterate { // Constructeur surchargé de la classe Iterate: public Iterate(Button mybtnIterate, Button mybtnReinit, TextBox mytxtInput, Label mylblState, int myentree, BackgroundWorker worker, DoWorkEventArgs e) { int pourcent = 0; int var0 = 0, var1; mybtnIterate.Enabled = false; mytxtInput.Focus(); do { var1 = 0; do { ++var1; } while (var1 < myentree); ++var0; pourcent = (var0 / myentree) * 100; worker.ReportProgress(pourcent); } while (var0 < myentree); mylblState.Text = "Terminé !"; mytxtInput.Enabled = false; }
}
and this is the problem:
The type or namespace name 'BackGroundWorker' could not be found (are you missing a using directive or an assembly reference?)
Does someone have an idea?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.
Try to add:
using System.ComponentModel;
Class name is BackgroundWorker, not BackGroundWorker - that's why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With