How to do a non-waiting write on a named pipe (c#)?

痴心易碎 提交于 2019-12-31 07:20:08

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3015748/how-to-do-a-non-waiting-write-on-a-named-pipe-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!