Joe
Joe

Reputation: 1103

NamedPipeServerStream C# proper usage - I keep getting IOExceptions

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.

Upvotes: 1

Views: 2149

Answers (1)

dustyburwell
dustyburwell

Reputation: 5813

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!

Upvotes: 2

Related Questions