Windows Phone 7 DownloadStringCompleted和url是什么?还是参考?

lac*_*cas 2 c# windows-phone-7

    private void button7_Click(object sender, RoutedEventArgs e)
    {
        WebClient client = new WebClient();
        client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
        client.DownloadStringAsync(new Uri("http://asd.com/bb"));
    }

    void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            MessageBox.Show(e.Result);

        }
        else {
            MessageBox.Show("err: " + e.Error.ToString());
        }
    }
Run Code Online (Sandbox Code Playgroud)

我如何从DownloadStringCompleted获取网址?或者我如何将一些参数传递给我的DownloadStringCompleted?

请帮忙

alf*_*alf 5

您可以通过DownloadStringAsync的第二个参数传递任何对象.然后,您可以通过DownloadStringCompletedEventArgs .UserState 检索该对象.

private void button7_Click(object sender, RoutedEventArgs e)
{
    WebClient client = new WebClient();
    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
    var uri = new Uri("http://asd.com/bb");
    client.DownloadStringAsync(uri, uri);
}

void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    var uri = e.UserState as Uri;
    //...
}
Run Code Online (Sandbox Code Playgroud)