开发者

Concurrent reading and writing to NamePipeClientStream

开发者 https://www.devze.com 2022-12-22 13:08 出处:网络
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 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 thr开发者_高级运维eads calling the same method and not separate threads calling separate methods like Read and Write?

Thanks!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号