0

如何在 Silverlight 中重新创建以下代码?当谈到异步时,我很迷茫。

public class StringGet 
{ 
    public static string GetPageAsString(Uri address) 
    { 
        string result = ""; 

        // Create the web request 
        HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest; 

        // Get response 
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) 
        { 
            // Get the response stream 
            StreamReader reader = new StreamReader(response.GetResponseStream()); 

            // Read the whole contents and return as a string 
            result = reader.ReadToEnd(); 
        } 
        return result; 
    } 
4

1 回答 1

-1
public void DownloadHtml(Uri address){
  WebClient webClient = new WebClient();
  webClient.DownloadStringCompleted += WebClientDownloadString_Complete;
  webClient.DownloadStringAsync(address)
}

private void WebClientDownloadString_Complete(object sender, DownloadStringCompletedEventArgs e) {
  if (e.Error == null) {
    string html = e.Result;
  }
}
于 2012-09-14T02:05:36.767 回答