Use of async methods in Silverlight sockets

May 30, 2012 at 7:54 PM

Hi,

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 (http://msdn.microsoft.com/en-us/library/system.net.sockets.socket%28v=vs.95%29.aspx)

A nice post about this
http://www.pitorque.de/MisterGoodcat/post/Windows-Phone-7-Mango-Sockets.aspx

Regards,