Cancel NamedPipeClientStream.Read call

I have looked all over the Internet, but I cannot find the answer to the following question.

I have a C # /. NET instance NamedPipeClientStream in a client program, and the workflow calls NamedPipeClientStream.Read (byte [], int, int) to receive data from the server. The server sends data updates to the client.

Reading is a blocking call. If I want to close the client, is there a way to cancel / withdraw the Read call? I tried calling Close on the named pipe instance, but it does not affect the thread called Read.

I would think that there is a way to cancel the awakening. If not, it looks like this is a very poorly designed API because your program is in the power of the pipe.

Any information is appreciated.

-Chris

+5
source share
2 answers

Use the NamedPipeClientStream constructor, which takes a PipeOptions argument. Specifying PipeOptions.Asynchronous will end the Read () call when you call the Close () method. The Read () method returns 0.

+7
source

This is not a direct answer to your question, but - I had to do a few NamedPipe IPCs quite recently, and I found that WCF was awesome. It took me less than an hour to complete the POC, and yes, I'm sure it provides the means to cancel your request - and you don't need to think about byte arrays.

Is this an option for you?

0
source

All Articles