I was messing around with Silverlight TCP communication, and I had to use the System.Net.Sockets.Socket class, which at run time Silverlight has only asynchronous methods.
I was wondering what would happen if two threads call SendAsync on a Socket instance in a very short time, one from the other?
My only concern is to not have mixed bytes passing through the TCP channel.
Being an asynchronous method , I suppose a message is placed in a queue from which one thread is deleted, so such events do not occur (mixing the contents of the message on the wire).
But I'm not sure, and MSDN does not indicate anything in the method description. Is anyone sure of this?
EDIT1: No, locking the object before calling SendAsync, for example:
lock(this._syncObj)
{
this._socket.SendAsync(arguments);
}
will not help, as it serializes requests to send data, not sent data.
source
share