Skip to content

Instantly share code, notes, and snippets.

@JeffreyZhao
Last active August 29, 2015 13:58

Revisions

  1. JeffreyZhao revised this gist Apr 4, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion WebClientExtensions.cs
    Original 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:照抄是不符合需求的。
    // 提示 2:照抄是不符合需求的,各方面都想清楚了再提交。
    // 提示 3:不要在回复区提交大段代码。可以创建新的Gist,然后提交链接。
    }
    }
  2. JeffreyZhao created this gist Apr 4, 2014.
    19 changes: 19 additions & 0 deletions WebClientExtensions.cs
    Original 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:照抄是不符合需求的。
    }
    }