tags:

views:

110

answers:

2

What the title says, really.

I have a named pipe. I would like to attempt a read, but if it doesn't succeed after a timeout I'd like to still be able to use the pipe afterwards.

Is this possible with NamedPipeServerStream, or do I have to rethink the entire approach?

So far the only way I've found of cancelling a BeginRead is by disposing of the pipe.

A: 

The BeginRead returns an IAsyncResult, capture this in the scope of the class.

Then create a timer with the desired timeout, in the callback method call EndRead, passing the IAsyncResult returned from the initial BeginRead.

Edit: I have been doing some research and the best solution I have found is to dispose of the ServerStream (which does dispose of the Pipe itself).

gooch
EndRead blocks until something has been read. How do I prevent that?
romkyns
You are correct, sorry for the misleading answer.
gooch
A: 

For the record, I didn't find a way. I still cancel a read that is taking too long by disposing of the stream, meaning that it can't be used at all afterwards.

romkyns