我使用命名管道使用.Net 3.5在两个进程之间进行通信。这在Windows 7上运行良好,但不知何故不在Windows XP下运行。
我在那里得到一个InvalidOperationException。这是我尝试翻译德语消息:“管道句柄尚未设置。您的PipeStream实现是否调用了InitializeHandle?”
我为此创建了一个测试项目:http://www.chinery.de/dateien/NamedPipeTest.zip
在应用程序中,您可以点击“连接”并看到管道的名称。在右侧,如果一切顺利,您可以输入将通过管道发送的消息。
正如我所说,问题只出现在Windows XP上。
有没有人对此有所了解?
我终于找到了解决方案。这是管道客户端的创建:
NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost", PipeName, PipeDirection.InOut)
我不得不将其更改为:NamedPipeClientStream pipeClient = new NamedPipeClientStream(“。”,PipeName,PipeDirection.InOut)
(将服务器名称从“localhost”更改为“。”)
这在某种程度上适用于Windows 7,但不适用于XP。现在它最终适用于两个系统。
它可能有权限问题:因此,需要提供所需的访问权限。
PipeSecurity _pipeSecurity = new PipeSecurity();
PipeAccessRule psEveryone = new PipeAccessRule("Everyone", PipeAccessRights.FullControl,
System.Security.AccessControl.AccessControlType.Allow);
_pipeSecurity.AddAccessRule(psEveryone);
NamedPipeServerStream pipeServer = new NamedPipeServerStream(PipeName, PipeDirection.In,
1, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 4, 4, _pipeSecurity);
并且只需按一下步骤即可解决监听问题:右键单击相应的服务>属性>登录>登录为:本地系统帐户,然后勾选允许服务与桌面交互。或者转到ServiceProcessInstaller属性并将帐户设置为LocalSystem。
我最近自己遇到了这个问题。我的解决方案是在调用NamedPipeClientStream.ReadMode
之后设置NamedPipeClientStream.Connect()
。否则我会得到上面提到的Pipe handle has not been set. Did your PipeStream implementation call InitializeHandle?
例外。