Are Asynchronous writes to a socket thread safe?
asynchronous, c#, io, sockets, thread-safety
Solution
I found a smiliar post on the MSDN forum which seems to answer to your question.
- You can queue multiple BeginSends at the same time. You don't need to lock
Edit:
Even more interesting informations:
If you scroll down a bit in the Remark section of the MSDN doc BeginSend(), you will find interesting use of callback methods that could be relevant for you.
[...] If you want the original thread to block after you call the BeginSend method, use the WaitHandle.WaitOne method. [...]
Problem
Consider the `Socket.BeginSend()` method. If two thread pool threads were to call this method simultaneously, would their respective messages end up mixing with each other or does the socket class keep this from happening?