Is it possible to cancel the BeginRead on the NamedPipeServerStream without closing the pipe?

What the title says, really.

I have a named pipe. I would like to try to read, but if it fails after the timeout, I would still be able to use this channel later.

Is this possible with NamedPipeServerStream

, or do I need to rethink the whole approach?

So far, the only way to cancel BeginRead

is to remove it from the channel.

+2


a source to share


2 answers


For the record, I couldn't find a way. I am still canceling a read that takes too long to get rid of the thread, which means it cannot be used afterwards.



0


a source


BeginRead

returns IAsyncResult

commits this to the scope of the class.

Then, create a timer with the required timeout, in the callback method call EndRead

, passing IAsyncResult

in the returned from the initial one BeginRead

.



Edit: I am doing some research and the best solution I have found is to get rid of the ServerStream (which does destroy the Pipe itself).

-2


a source







All Articles