如何在方法中调用BackgroundWorker.ReportProgress? [英] How to call BackgroundWorker.ReportProgress in a method?
本文介绍了如何在方法中调用BackgroundWorker.ReportProgress?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以做这样的事情吗?
Hi, there is any way to do something like this?
public void mybw_DoWork(object sender, DoWorkEventArgs e){
...
while(...){
...
mymetod();
....
}
....
}
public void mymetod() {
...
...
//Here i want to call mybw.ReportProgress, how can i do this?
...
...
}
我确定这是一个愚蠢的问题,但我不知道该怎么办:/
I'm sure this is a stupid question, but i dont know how to do :/
推荐答案
查看MSDN上的示例:
[ ^ ]
你必须投您的发件人参数类型为BackgroundWorker:
Have a look at the example on MSDN:
[^]
You have to cast your sender argument to type BackgroundWorker:
BackgroundWorker worker = sender as BackgroundWorker;
那么你可以把那个工人传给我作为一个论点。
Then you can pass that worker into mymethod as an argument.
public void mymetod(BackgroundWorker worker)
{
worker.ReportProgress(...);
}
CodeProject上有一个很好的教程:[ ^ ]。
你会想要在BackGroundWorker的'DoWork EventHandler中的代码中显示'while循环...或其他导致多次迭代代码的其他内容。
There's a good tutorial here on CodeProject: [^].
You will want to locate the 'while loop ... or whatever else causes multiple iterations of exceuting code ... shown in your code in the BackGroundWorker's 'DoWork EventHandler.
这篇关于如何在方法中调用BackgroundWorker.ReportProgress?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文