Skip to content

Instantly share code, notes, and snippets.

@JeffreyZhao
Last active August 29, 2015 13:58
Show Gist options
  • Save JeffreyZhao/9967023 to your computer and use it in GitHub Desktop.
Save JeffreyZhao/9967023 to your computer and use it in GitHub Desktop.
// 添加一个扩展方法
public static class WebClientExtensions {
public static Task<string> DownloadStringAsync(
this WebClient client,
Uri uri,
CancellationToken cancellationToken,
int timeout) {
// 部分可能涉及到的API:
client.DownloadStringCompleted += (sender, args) => { /* ... */ };
client.DownloadStringAsync(uri);
client.CancelAsync();
// 提示 1:可参考 .NET 4.5 中 DownloadStringTaskAsync 的实现 (http://referencesource.microsoft.com/#System/net/System/Net/webclient.cs#c7637e8144774520)
// 提示 2:照抄是不符合需求的,各方面都想清楚了再提交。
// 提示 3:不要在回复区提交大段代码。可以创建新的Gist,然后提交链接。
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment