DownloadStringCompletedEventArgs 类    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 DownloadStringCompleted 事件提供数据。
public ref class DownloadStringCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgspublic class DownloadStringCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgstype DownloadStringCompletedEventArgs = class
    inherit AsyncCompletedEventArgsPublic Class DownloadStringCompletedEventArgs
Inherits AsyncCompletedEventArgs- 继承
示例
下面的代码示例演示如何异步下载字符串。
// Sample call : DownloadStringInBackground2 ("http://www.contoso.com/GameScores.html");
public static void DownloadStringInBackground2(string address)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(address);
    // Specify that the DownloadStringCallback2 method gets called
    // when the download completes.
    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCallback2);
    client.DownloadStringAsync(uri);
}
'  Sample call : DownloadStringInBackground2 ("http:' www.contoso.com/GameScores.html")
Public Shared Sub DownloadStringInBackground2(ByVal address As String)
    Dim client As WebClient = New WebClient()
    '  Specify that the DownloadStringCallback2 method gets called
    '  when the download completes.
    AddHandler client.DownloadStringCompleted, AddressOf DownloadStringCallback2
                Dim uri as Uri = New Uri(address)
    client.DownloadStringAsync(uri)
End Sub
下载完成后,将调用以下方法。
private static void DownloadStringCallback2(Object sender, DownloadStringCompletedEventArgs e)
{
    // If the request was not canceled and did not throw
    // an exception, display the resource.
    if (!e.Cancelled && e.Error == null)
    {
        string textString = (string)e.Result;
        Console.WriteLine(textString);
    }
}
Private Shared Sub DownloadStringCallback2(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
    '  If the request was not canceled and did not throw
    '  an exception, display the resource.
    If e.Cancelled = False AndAlso e.Error Is Nothing Then
        Dim textString As String = CStr(e.Result)
        Console.WriteLine(textString)
    End If
End Sub
注解
此类的实例将传递给 DownloadStringCompletedEventHandler。
属性
| Cancelled | 获取一个值,该值指示异步操作是否已被取消。(继承自 AsyncCompletedEventArgs) | 
| Error | 获取一个值,该值指示异步操作期间发生的错误。(继承自 AsyncCompletedEventArgs) | 
| Result | 获取由 DownloadStringAsync 方法下载的数据。 | 
| UserState | 获取异步任务的唯一标识符。(继承自 AsyncCompletedEventArgs) | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| RaiseExceptionIfNecessary() | 如果异步操作失败,则引发用户提供的异常。(继承自 AsyncCompletedEventArgs) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |