views:

48

answers:

1

I've been searching for a while but it seems to be difficult to find any definite answers on how to recover from exceptions thrown by calling NamedPipeServerStream.BeginWaitForConnection. I have an application that sets up a named pipe server on a well known name and listens for messages to perform certain actions.

It works fine and dandy until the application is restarted. This usually results in an IOException saying, "The pipe is being closed." How can I correctly recover from this exception and use the same name for my named pipe? Any good resources on a good production worthy implementation of a named pipe server would be appreciated.

+1  A: 

If you're sending the message immediately after starting the process. You should call wait for pipe drain before closing the handle. Make sure to WaitForPipeDrain on the stream before close.

- Good luck!

dustyburwell
Wow! this worked for me because I tried sending a message to the pipe as the process was starting. But I closed the client connection before the server had a chance to start up. Calling waitforpipedrain before close ensured that the server connected to the pipe before I closed the handle.
Joe