Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
The algorithm for getting an answer to your question, which I used and also advise you:
1. Let's go and see what type of stream TcpClient.GetStream() returns . Stream type - NetworkStream.
2. We follow the link to NetworkStream and go down to the Thread Safety section - all classes have it, this is a standard documentation element. It says:
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Those. It says that only static methods are thread-safe. This phrase is found in most classes, because. most were not designed specifically for multithreading. Here concurrent collections are a different matter, they have it written (queue ):
All public and protected members of ConcurrentQueue are thread-safe and may be used concurrently from multiple threads.
Which is logical, because in inter-thread locks, the whole point of this queue, unlike the usual one.
Please note that the fact that you read with only one stream and write with the other does not mean at all that they will not interfere with each other. For example, both reading and writing can change some internal pointers and indices (the number of the current byte or how many more unread bytes are left), which you cannot even know about. Therefore, we always go to the documentation and check what is there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question