.NET C#匿名管道 - 被误读? [英] .net c# Anonymous Pipes - Misunderstood?

查看:493
本文介绍了.NET C#匿名管道 - 被误读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父Windows窗体应用程序和一个孩子commandline.exe。用改进的MSDN例如匿名管道(H TTP://msdn.microsoft.com /en-us/library/bb546102.aspx )我能够从父发送一个序列化对象的孩子。孩子可以deserialise对象,并读出值。

I have a parent windows form application and a child commandline.exe. Using a modified MSDN example for anonymous pipes (http://msdn.microsoft.com/en-us/library/bb546102.aspx) I am able to send a serialised object from the parent to the child. The child can deserialise the object and read the values.

也许我误解了匿名管道的机制,但是我期待管道保持打开状态,直到我关闭它,使我能够发送另一个对象时,我喜欢过,但是之后的对象是发送/接收的管不再连接(通过IsConnected属性决定)。

Perhaps I misunderstand the mechanics of the anonymous pipe, however I am expecting the pipe to remain open until I close it, so that I am able to send another object across when I like, however after the object is send/received the pipe is no longer connected (determined by IsConnected property).

目前,一旦对象是由父母送到孩子,在管道关闭(而不是我)。我保持一个参照原有pipeHandle本地,但似乎无法重新打开管道。我应该能够或者应该不会在第一时间关闭?我不明白我怎么能打开另一个新的管道,因为我不能从父句柄传递到客户端(初始pipehandle被一审经过参数)

At the moment, once an object is sent from parent to child, the pipe is closed (not by "me"). I maintain a reference to the original pipeHandle locally but cannot seem to re-open the pipe. Should I be able to or should it not have closed in the first place? I don't see how I could open another new pipe, as I cannot pass the handle from the parent to the client (the initial pipehandle was passed by args in the first instance)

我如何从父母送孩子另一个对象?

How do I send another object from the parent to the child?

我知道我可以使用命名管道,但MSDN建议在同一本地计算机上的匿名管道IPC。

I realise I can use Named-Pipes, but MSDN recommends anonymous pipes for IPC on the same local machine.

感谢

阿尼

推荐答案

如果你正在做类似的MSDN样本中你是关闭的StreamWriter(与使用语句)和关闭的StreamWriter 关闭底层流。管道保持打开状态,只要流保持打开,所以如果你不想关闭它,不要关闭该流也不是的StreamWriter

If you're doing like in the MSDN sample you are closing the StreamWriter (with the using statement), and closing a StreamWriter closes the underlying stream. The pipe remains open as long as the stream remains open, so if you don't want to close it, don't close the stream nor the StreamWriter.

这篇关于.NET C#匿名管道 - 被误读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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