TPL TaskFactory.FromAsync vs Tasks with blocking methods

You absolutely want to use FromAsync when an API offers a BeginXXX/EndXXX version of a method. The difference is that, in the case of something like Stream or Socket or WebRequest, you’ll actually end up using async I/O underneath the covers (e.g. I/O Completion Ports on Windows) which is far more efficient than blocking multiple … Read more

How to check if TcpClient Connection is closed?

I wouldn’t recommend you to try write just for testing the socket. And don’t relay on .NET’s Connected property either. If you want to know if the remote end point is still active, you can use TcpConnectionInformation: TcpClient client = new TcpClient(host, port); IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections().Where(x => x.LocalEndPoint.Equals(client.Client.LocalEndPoint) && x.RemoteEndPoint.Equals(client.Client.RemoteEndPoint)).ToArray(); … Read more