Last active
August 29, 2015 13:58
Revisions
-
JeffreyZhao revised this gist
Apr 4, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public static Task<string> DownloadStringAsync( client.CancelAsync(); // 提示 1:可参考 .NET 4.5 中 DownloadStringTaskAsync 的实现 (http://referencesource.microsoft.com/#System/net/System/Net/webclient.cs#c7637e8144774520) // 提示 2:照抄是不符合需求的,各方面都想清楚了再提交。 // 提示 3:不要在回复区提交大段代码。可以创建新的Gist,然后提交链接。 } } -
JeffreyZhao created this gist
Apr 4, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ // 添加一个扩展方法 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:照抄是不符合需求的。 } }