5
我用我的.NET应用程序创建了一个命名管道服务器,它的名字是“TSPipe”。然后我打开记事本并尝试将文件保存到“\。\ pipe \ TSPipe”。然后,我希望能够阅读记事本写入该管道的内容。在Windows上,我可以使用命名管道作为文件吗?
我还在工作了一般逻辑处理该NamedPipeServerStream,但这里是我的代码命名管道服务器线程:
public void PipeThread() {
var sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
var rule = new PipeAccessRule(sid, PipeAccessRights.ReadWrite, AccessControlType.Allow);
var sec = new PipeSecurity();
sec.AddAccessRule(rule);
while (continuePipeThread) {
pipeStream = new NamedPipeServerStream("TSPipe", PipeDirection.In, 100, PipeTransmissionMode.Byte, PipeOptions.None, 0, 0, sec);
Program.Output.PrintLine("Waiting for connection...");
pipeStream.WaitForConnection();
Program.Output.PrintLine("Connected, reading...");
byte[] data = new byte[1024];
int lenRead = 0;
lenRead = pipeStream.Read(data, 0, data.Length);
string line = System.Text.Encoding.ASCII.GetString(data, 0, lenRead);
Program.Output.PrintLine(line);
pipeStream.Close();
pipeStream.Dispose();
}
}
在此先感谢您的帮助,但我会让你知道是否有任何建议帮助!
好的,谢谢。这回答了我的问题。我想我必须找到另一种方式来做IPC。 – Tim
它会发送文本吗?它不适合我。 (Win7,提升'cmd') –