0

困扰我一整天的问题是我启动了大约200个线程,每个线程都会调用该方法,该方法将调用该方法内部的webservice。

当我打开 TCPView 时,我只能看到客户端进程与 WCF 服务器之间的大约 20 个连接。

我不打算使用 PLINQ 或 ThreadPool,因为每个线程可能需要很长时间来计算然后返回,

我的客户端线程部分代码如下:

for (int i = 0; i < inputs.Count(); i++)
{
    Thread t = new Thread(new ParameterizedThreadStart(InnerCalculate));
    t.Start(new ThreadParameter()
        {
            Index = i,
            Count = inputs.Count
        });

    threads.Add(t);
    Thread.Sleep(200);
}

foreach (Thread thread in threads)
{
    thread.Join();
}

行为的服务端配置如下:

    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentInstances="6"/>
    </behavior>

谁能告诉我我错在哪里?或者问题可能发生在哪里?谢谢!

4

1 回答 1

1

Is this not just WCF throttling the number of concurrent connections available? Your measurement of 20 is only an indirect indication of what's going on, chances are you really do have the full 200 threads but only 20 can connect at a time.

于 2013-07-02T14:42:55.037 回答