I'm using a StreamReader to read from a TcpSocket, and a StreamWriter to write to that TcpSocket. I would like to have the reading code in one thread and the writing code in another. How do I do this in a thread-safe manner?
If I do the following, then I guess the writer thread will be blocked in many cases:
lock (tcpClient) {
    streamReader.ReadLine();
}
Here would be the writer code:
lock (tcpClient) {
    streamWriter.WriteLine(line);
}
开发者_JAVA技巧It is safe to send on one thread and receive on the other thread.
So you can do this in one thread:
streamReader.ReadLine();
and this in another thread:
streamWriter.WriteLine(line);
without having to lock the tcpClient.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论