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);
}