views:

161

answers:

1

I have a NamedPipeClientStream instance in my application that is setup for duplex communication (PipeDirection.InOut). I also have two threads, a read thread and a write thread.

I want to have the read thread call only the NamedPipeClientStream.Read method, and the write thread only call the NamedPipeClientStream.Write method. They will never be calling each others methods, but they may be making calls to the pipe instance at the same time.

I looked up the documentation for the NamedPipeClientStream and it said that public static methods are thread safe, but instance methods are not guaranteed to be thread safe.

My question is is it safe that I have two threads calling two different methods (Read and Write) on the pipe instance at the same time, or is this something I should not do? And, does the instance method thread safety only apply to separate threads calling the same method and not separate threads calling separate methods like Read and Write?

Thanks!

+1  A: 

Yes, no problem. Both PipeStream.Read and Write directly call the native Windows API, ReadFile and WriteFile are thread safe.

Hans Passant
Excellent, this is what I needed to know. Thanks!
Chris