This is in the documentation you are attached to .
Generally, you should first review or ask for updated APIs that support TAP directly. Almost all BCL classes have already been updated to support TAP, and several (for example, HttpWebRequest ) have been replaced by alternatives to TAP (for example, HttpClient ). In this case, there is no equivalent to TAP TcpClient , so their packaging is the best choice.
If you are writing TAP on top of APM wrappers, I recommend using simple extension methods:
public static Task ConnectTaskAsync(this TcpClient client, IPAddress address, int port) { return Task.Factory.FromAsync(client.BeginConnect, client.EndConnect, address, port, null); }
This gives you a natural way to destroy them and separates your "interop" code from any code that contains actual logic:
async Task SomeMethodAsync() { this.tcpClient = new TcpClient(); await this.tcpClient.ConnectTaskAsync(ip, port);
Stephen cleary
source share