【发布时间】:2010-11-22 06:12:23
【问题描述】:
我试图绕过 .net 3.5 强加的 wait64 句柄限制
我看过这个帖子:Workaround for the WaitHandle.WaitAll 64 handle limit?
所以我理解大意,但我遇到了困难,因为我没有使用委托,而是使用了
我基本上是在处理这个例子: http://msdn.microsoft.com/en-us/library/3dasc8as%28VS.80%29.aspx
此链接http://www.switchonthecode.com/tutorials/csharp-tutorial-using-the-threadpool 类似,但跟踪任务的 int 变量也是成员变量。
在上面的例子中,我应该在哪里传递 threadCount 整数? 我是否将它作为对象传递给回调方法?我认为我在使用回调方法和通过引用传递时遇到了问题。
谢谢斯蒂芬,
该链接对我来说并不完全清楚。
让我发布我的代码以帮助自己澄清:
for (int flows = 0; flows < NumFlows; flows++)
{
ResetEvents[flows] = new ManualResetEvent(false);
ICalculator calculator = new NewtonRaphson(Perturbations);
Calculators[flows] = calculator;
ThreadPool.QueueUserWorkItem(calculator.ThreadPoolCallback, flows);
}
resetEvent.WaitOne();
我将在哪里传递我的 threadCount 变量。我认为它需要在calculator.ThreadPoolCallback 中递减?
【问题讨论】:
-
对不起,我相信我的意思是第一个链接中的“threadCount”。
-
次要技术点:64 个句柄的限制是由 Win32 API 施加的,而不是 .NET 3.5。因此,Windows 上的每个程序都有相同的限制。
标签: c# multithreading threadpool