BackgroundWorker的匿名方法? [英] BackgroundWorker with anonymous methods?
本文介绍了BackgroundWorker的匿名方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要创建一个的BackgroundWorker 与匿名方法。
我已经写了下面的code:
I'm gonna create a BackgroundWorker with an anonymous method.
I've written the following code :
BackgroundWorker bgw = new BackgroundWorker();
bgw.DoWork += new DoWorkEventHandler(
() =>
{
int i = 0;
foreach (var item in query2)
{
....
....
}
}
);
但 委托System.ComponentModel.DoWorkEventHandler'不走'0'参数的,我必须通过两个对象,以匿名方式:对象发件人,DoWorkEventArgsê
能否请你指导我,我该怎么办呢? 谢谢你。
Could you please guide me, how I can do it ? Thanks.
推荐答案
您只需要参数添加到匿名函数:
You just need to add parameters to the anonymous function:
bgw.DoWork += (sender, e) => { ... }
或者,如果你不关心的参数,你可以:
Or if you don't care about the parameters you can just:
bgw.DoWork += delegate { ... }
这篇关于BackgroundWorker的匿名方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文