如何对命名管道(c#)执行不等待写操作? [英] How to do a non-waiting write on a named pipe (c#)?

查看:657
本文介绍了如何对命名管道(c#)执行不等待写操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用.net 3.5命名管道,我的服务器端是:

I'm using .net 3.5 named pipes and my server side is :

serverPipeStream = new NamedPipeServerStream("myPipe", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

当我用BinaryWriter写一些数据时,write()调用本身不返回直到客户端在其NamedPipeClientStream上调用read()。

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.

BinaryWriter是:

The BinaryWriter is :

writer = new BinaryWriter(serverPipeStream);

我知道NamedPipeServerStream提供了一个BeginRead / BeginWrite,但从我收集,命名管道(如许多Microsoft给出的例子中所示)。

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).

那么如何使我的write()

So how can I make my write() to the named pipe non-waiting ?

感谢您提供任何帮助。

推荐答案

问题是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.

希望有帮助。

这篇关于如何对命名管道(c#)执行不等待写操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆