如何在命名管道(c#)上进行非等待写入?
我正在使用 .net 3.5 命名管道,我的服务器端是:
serverPipeStream = new NamedPipeServerStream("myPipe", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
当我使用 BinaryWriter 写入一些数据时,write() 调用本身不会返回,直到客户端在其 NamedPipeClientStream 上调用 read() 。
BinaryWriter 是:
writer = new BinaryWriter(serverPipeStream);
我知道 NamedPipeServerStream 提供了 BeginRead/BeginWrite,但从我收集的情况来看,命名管道应该允许流编写器在它们之上执行(如许多 Microsoft 给出的示例中所示)。
那么我怎样才能使我的 write() 到命名管道不等待呢?
预先感谢您的任何帮助。
I'm using .net 3.5 named pipes and my server side is :
serverPipeStream = new NamedPipeServerStream("myPipe", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
When I write some data with, say, BinaryWriter, the write() call itself doesn't return until the client side has called a read() on its NamedPipeClientStream.
The BinaryWriter is :
writer = new BinaryWriter(serverPipeStream);
I'm aware that NamedPipeServerStream offers a BeginRead/BeginWrite but from what I gather, named pipes are supposed to allow streamwriters to perform on top of them (as seen in many Microsoft-given examples).
So how can I make my write() to the named pipe non-waiting ?
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 BinaryWriter 没有
BeginWrite
函数,因此,按照建议 此处,您可以写入MemoryStream ,然后使用其缓冲区传递给管道的BeginWrite
函数。希望有帮助。
The problem is BinaryWriter doesn't have a
BeginWrite
function so, as suggested here, you could write to a MemoryStream and then use the its buffer to pass to theBeginWrite
function of the pipe.Hope that helps.