PipeStream (NamedPipe) Read existing Pipe Problem with EndRead/ notimeout

P

Peter

Hi

Please help me with System.IO.Pipes;

i use
this.pipe = new NamedPipeClientStream(".", "S036X",
PipeDirection.InOut, PipeOptions.Asynchronous);
pipe.Connect(200);

to connect an existing Pipe which is provided by an 3rd party
Application.

Connecting, Writing and reading the pipe works mostly fine.

But !! sometimes reading the Pipe blocks my App.
I think it happend when the pipe is empty (i can force it reading the
pipe right after pipe.Connect(), without sending a command to the pipe-
Server)

is there a possibility to find out whether data present in the pipe ?

I try

sr = new StreamReader(pipe);
string data = sr.ReadToEnd();

or.

IAsyncResult ar = pipe.BeginRead(buffer, 0, 255, null, null);
if (ar.AsyncWaitHandle.WaitOne(1000) == true)
{
// ok if Data Present
int read = pipe.EndRead(ar);
......
}
else
{
// cont. here after 1000 ms but pipe.EndRead... blocks the
App !!
// msdn says EndRead must be calle for each BeginRead
pipe.EndRead(ar);
}

------

setting pipe.ReadTimeout = 1000 is not supportet.
reading pipe.Length is not supported.

What can I do. ?

Thank you.
Peter
 
Top