如何在命名管道(c#)上进行非等待写入?

发布于 2024-09-05 16:29:30 字数 557 浏览 6 评论 0原文

我正在使用 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2024-09-12 16:29:30

问题是 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 the BeginWrite function of the pipe.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文