Use of async methods in Silverlight sockets

May 30, 2012 at 8:54 PM


I was checking the socket implementation and I notice that you are not paying attention to the return value when calling async methods (SendAsync, ReceiveAsync, ConnectAsync). This value let you know if the callback function will be called asynchronously or if the process was done synchronously. In the second situation, you need to call the callback function by yourself.

Something like:

bool async = this.Socket.ReceiveAsync(e);
if (!async) callback(this.Socket,e);

You can check the MSDN documentation for sockets in the Silverlight framework (

A nice post about this