ThreadPool.QueueUserWorkItem用例 [英] ThreadPool.QueueUserWorkItem use case
本文介绍了ThreadPool.QueueUserWorkItem用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用该方法是这样的:
I'm trying to use that method this way:
public void Method()
{
ThreadPool.QueueUserWorkItem(() =>
{
while(!paused)
{
ThreadPool.QueueUserWorkItem(() => {...);
}
});
}
}
在问题出现的原因,它抛出我的编译错误。第一次调用
The problem comes cause it throws me a compilation error in the first call.
错误CS1593:代理 System.Threading.WaitCallback不采取
0的论点
error CS1593: Delegate
System.Threading.WaitCallback' does not take
0' arguments
中如何做到这一点不带参数任何想法? ?,任何其他
Any idea of how to do it without arguments? , any alternative?
推荐答案
您只需提供lambda表达式的参数,而忽略它:
You can just provide a parameter for the lambda expression, and ignore it:
ThreadPool.QueueUserWorkItem(ignored =>
{
while(!paused)
{
ThreadPool.QueueUserWorkItem(alsoIgnored => {...});
}
});
或者使用,而不是一个匿名方法:
Or use an anonymous method instead:
ThreadPool.QueueUserWorkItem(delegate
{
while(!paused)
{
ThreadPool.QueueUserWorkItem(delegate {...});
}
});
如果你不关心匿名方法的参数,你不必说出它们。
If you don't care about parameters for anonymous methods, you don't have to state them.
这篇关于ThreadPool.QueueUserWorkItem用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文