I\'m teaching myself to use pipes and I have two apps, one with the PipeServer class and one with the PipeClient class (shown below). The server app creates an instance of
StreamReader closes stream passed to it after disposal, and you are disposing StreamReader in the end of using (StreamReader sr = new StreamReader(_pipeClient))
block.
You can create StreamReader at class level in constructor, and use it in ReadMessages method
public PipeClient(string pipeName)
{
_pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.In);
_pipeClient.Connect();
_streamReader = new StreamReader(_pipeClient);
}
public void ReadMessages()
{
string temp;
while ((temp = _streamReader.ReadLine()) != null)
if(MessageReadEvent != null)
MessageReadEvent(temp);
}