"Ken Allen" <ke******@sympatico.ca> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...
Is there any built-in facility for handling named pipes in C#/.Net, or
must one use unsafe code to access the WIN32 API directly?
There exists some code that uses named pipes heavily and there exists a
need for that code to send some information to a new .Net service I am writing.
It is a relatively simple matter for the existing code to use a named pipe
to send the data, but I can find no references to how I can create the
named pipe and manage it from the .Net side.
You must use Win32 to create or open the named pipe, but once you have a
handle to the named pipe, you can just wrap it in a System.IO.FileStream to
read and write.
To replicate the example here
http://msdn.microsoft.com/library/de...ipe_server.asp
for a mutithreaded pipe server, it looks like you'll need to call
CreateNamedPipe
ConnectNamedPipe
DisconnectNamedPipe
CloseHandle
through P/Invoke.
The FileStream will take care of ReadFile, WriteFile, FlushFileBuffers and
CloseHandle on the connected pipe instance.
David