Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net c# Anonymous Pipes - Misunderstood?

Tags:

c#

.net

pipe

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.

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

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?

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

Many thanks

Arnie

like image 452
Arnie Avatar asked Jan 26 '11 17:01

Arnie


1 Answers

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.

like image 127
R. Martinho Fernandes Avatar answered Oct 06 '22 01:10

R. Martinho Fernandes