我有一个循环运行的程序,每次迭代都在不同的线程中运行,我正在创建打开新服务主机的新进程:
ServiceHost _host = new ServiceHost(_service, new Uri("net.pipe://localhost/" + i_PipeName));
_host.AddServiceEndpoint(typeof(ICommandService), new NetNamedPipeBinding() { TransferMode = TransferMode.Buffered }, i_PipeName);
_host.Open();
在我的主程序中,我通过以下方式连接到打开的 .net 管道:
ICommandService ServiceProxy = ChannelFactory<ICommandService>.CreateChannel
(new NetNamedPipeBinding(), new EndpointAddress(@"net.pipe://localhost/" + i_PipeName" + @"/" + i_PipeName));
所以我的问题是,对于前 200 多个过程/迭代,它工作正常,我可以打开连接并传递消息,但后来开始出现错误:
There was no endpoint listening at net.pipe://localhost/pipea0360/pipea0360 that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException if present, for more details.
我的问题是我可以并行打开的管道数量是否有任何限制?
是因为我开了太多进程吗?
最佳答案
您是否排除了竞争条件,即客户端试图连接到服务器尚未建立的管道?如果服务器上有很多事件线程,它很容易延迟应该开始监听的线程。这可以解释为什么它在一开始就有效。
一般来说,为每个客户端分配一个服务器线程并不能很好地扩展;您将通过线程池方法获得更好的性能。
关于c# - 什么是命名管道 (net.pipe) 限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12405134/