C# 中的BackgroundWorker 问题
我的组件“BackgroundWorker”有问题
当我单击按钮时,我必须执行 n 次迭代,这需要时间,并且我必须将此操作委托给
我遵循本教程的另一个线程: 教程(在french)
这是我的代码:
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 是我的 BackgroundWorker 组件 这是我想要委托的方法:
类迭代 { // 迭代类的附加构造函数: 公共迭代(按钮 mybtnIterate,按钮 mybtnReinit, 文本框 mytxtInput,标签 mylblState, int myentree,BackgroundWorker工人, DoWorkEventArgs e) { int 倾角 = 0; int var0 = 0, var1; mybtnIterate.Enabled = false; mytxtInput.Focus(); 做 { 变量1=0; 做 { ++var1; } while (var1 < myentree); ++var0; 浇注=(var0 / myentree)* 100; 工人.ReportProgress(pourcent); } while (var0 < myentre); mylblState.Text = "终止!"; mytxtInput.Enabled = false; }
}
就是问题所在:
找不到类型或命名空间名称“BackGroundWorker”(您是否缺少 using 指令或程序集引用?)
有人有想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试添加:
Try to add:
类名是BackgroundWorker,而不是BackGroundWorker - 这就是原因。
Class name is BackgroundWorker, not BackGroundWorker - that's why.